#define sock_errno() WSAGetLastError()
#define sock_errstr(e) WSAGetErrorString(e)
+extern char* WSAGetErrorString LDAP_P((int));
+
#elif MACOS
# define tcp_close( s ) tcpclose( s )
# define tcp_read( s, buf, len ) tcpread( s, buf, len )
# define tcp_close( s ) close( s )
# define tcp_read( s, buf, len) read( s, buf, len )
# define tcp_write( s, buf, len) write( s, buf, len )
+
+#ifdef HAVE_PAIR
+#define USE_PAIR HAVE_PAIR
+#endif
+
#endif /* MACOS */
#ifndef ioctl_t
#ifndef AC_SOCKET_INVALID
# define AC_SOCKET_INVALID (-1)
#endif
+#ifndef AC_SOCKET_ERROR
+# define AC_SOCKET_ERROR (-1)
+#endif
#if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
#define inet_aton ldap_pvt_inet_aton
LBER_SOCKET_T sd;
sd = socket( AF_INET, SOCK_DGRAM, 0 );
- if (sd < 0)
+ if ( sd == AC_SOCKET_INVALID )
return sd;
(void) memset( (void*) &si, 0, len );
si.sin_port = 0;
si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
- if ( rc = bind( sd, (struct sockaddr *)&si, len ) ) {
+ rc = bind( sd, (struct sockaddr *)&si, len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
return rc;
}
- if ( rc = getsockname( sd, (struct sockaddr *)&si, &len ) ) {
+ rc = getsockname( sd, (struct sockaddr *)&si, &len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
return rc;
}
- if ( rc = connect( sd, (struct sockaddr *)&si, len ) ) {
+ rc = connect( sd, (struct sockaddr *)&si, len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
return rc;
}
#include "ldap_pvt.h"
#include "ldap_defaults.h"
+#include "lutil.h"
#include "slap.h"
#ifdef HAVE_TCPD
#ifdef SO_REUSEADDR
/* enable address reuse */
tmp = 1;
- if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
- (char *) &tmp, sizeof(tmp) ) == -1 )
- {
+ rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &tmp, sizeof(tmp) );
+ if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
#ifdef SO_KEEPALIVE
/* enable keep alives */
tmp = 1;
- if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE,
- (char *) &tmp, sizeof(tmp) ) == -1 )
- {
+ rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE,
+ (char *) &tmp, sizeof(tmp) );
+ if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_KEEPALIVE) failed errno=%d (%s)\n",
#ifdef TCP_NODELAY
/* enable no delay */
tmp = 1;
- if ( setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY,
- (char *)&tmp, sizeof(tmp) ) )
- {
+ rc = setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&tmp, sizeof(tmp) );
+ if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(TCP_NODELAY) failed errno=%d (%s)\n",
}
#endif
- if ( bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ) == -1 ) {
+ rc = bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) );
+ if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
* loop will be select'ing on this socket, and will wake up when
* this byte arrives.
*/
- if( (rc = lutil_pair( wake_sds )) < 0 )
- {
+ if( (rc = lutil_pair( wake_sds )) < 0 ) {
Debug( LDAP_DEBUG_ANY,
"daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
return rc;
return 0;
}
-void hit_socket(void)
-{
- ber_socket_t s;
- int on = 1;
- extern struct sockaddr_in bind_addr;
-
- /* throw something at the socket to terminate the select() in the daemon thread. */
- if (( s = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID )
- Debug( LDAP_DEBUG_ANY,
- "slap_set_shutdown: socket failed\n\tWSAGetLastError=%d (%s)\n",
- WSAGetLastError(), WSAGetLastErrorString(), 0 );
-
- if ( ioctlsocket( s, FIONBIO, &on ) == -1 )
- Debug( LDAP_DEBUG_ANY,
- "slap_set_shutdown:FIONBIO ioctl on %d faled\n\tWSAGetLastError=%d (%s)\n",
- s, WSAGetLastError(), WSAGetLastError() );
-
- bind_addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
-
- if ( connect( s, (struct sockaddr *)&bind_addr, sizeof( struct sockaddr_in )) == SOCKET_ERROR ) {
- Debug( LDAP_DEBUG_ANY,
- "hit_socket: error on connect: %d\n",
- WSAGetLastError(), 0, 0 );
- /* we can probably expect some error to occur here, mostly WSAEWOULDBLOCK */
- }
-
- tcp_close(s);
-}
-
#elif HAVE_WINSOCK
static int sockinit(void)
-{ WSADATA wsaData;
+{
+ WSADATA wsaData;
if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
return -1;
}