Commit 9826f704 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Back out to simple sock_errno sock_errstr macros and use WSAGetErrorString

instead of WSAGetLastErrorString to preserve errno like semantics.
parent 5333a580
/* Generic socket.h */
/* $Id$ */
/* $Id: socket.h,v 1.28 1999/08/29 18:35:22 kdz Exp $ */
/*
* Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
......@@ -66,8 +66,10 @@
#define MAXHOSTNAMELEN 64
#endif
#define SOCK_ERR(num, str) \
num = errno; str = STRERROR(errno)
#undef sock_errno
#undef sock_errstr
#define sock_errno() errno
#define sock_errstr(e) STRERROR(e)
#ifdef HAVE_WINSOCK
# define tcp_close( s ) closesocket( s )
......@@ -81,9 +83,10 @@
#define EINPROGRESS WSAEINPROGRESS
#define ETIMEDOUT WSAETIMEDOUT
#undef SOCK_ERR
#define SOCK_ERR(num, str) \
num = WSAGetLastError(); str = WSAGetLastErrorString()
#undef sock_errno
#undef sock_errstr
#define sock_errno() WSAGetLastError()
#define sock_errstr(e) WSAGetErrorString(e)
#elif MACOS
# define tcp_close( s ) tcpclose( s )
......
......@@ -208,12 +208,10 @@ open_listener(
int port,
int tls_port )
{
int tmp, rc;
Listener l;
Listener *li;
LDAPURLDesc *lud;
int tmp, rc;
int err;
char *errstr;
char *s;
rc = ldap_url_parse( url, &lud );
......@@ -278,10 +276,10 @@ open_listener(
if ( (l.sl_sd = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID ) {
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: socket() failed errno=%d (%s)\n", err,
errstr, 0 );
sock_errstr(err), 0 );
return NULL;
}
......@@ -301,10 +299,10 @@ open_listener(
if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
(char *) &tmp, sizeof(tmp) ) == -1 )
{
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
(long) l.sl_sd, err, errstr );
(long) l.sl_sd, err, sock_errstr(err) );
}
#endif
#ifdef SO_KEEPALIVE
......@@ -313,10 +311,10 @@ open_listener(
if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE,
(char *) &tmp, sizeof(tmp) ) == -1 )
{
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_KEEPALIVE) failed errno=%d (%s)\n",
(long) l.sl_sd, err, errstr );
(long) l.sl_sd, err, sock_errstr(err) );
}
#endif
#ifdef TCP_NODELAY
......@@ -325,17 +323,17 @@ open_listener(
if ( setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY,
(char *)&tmp, sizeof(tmp) ) )
{
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(TCP_NODELAY) failed errno=%d (%s)\n",
(long) l.sl_sd, err, errstr );
(long) l.sl_sd, err, sock_errstr(err) );
}
#endif
if ( bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ) == -1 ) {
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
(long) l.sl_sd, err, errstr );
(long) l.sl_sd, err, sock_errstr(err) );
tcp_close( l.sl_sd );
return NULL;
}
......@@ -362,8 +360,6 @@ static int sockdestroy(void);
int slapd_daemon_init(char *urls, int port, int tls_port )
{
int i, rc;
int err;
char *errstr;
char **u;
#ifndef HAVE_TLS
......@@ -398,14 +394,15 @@ int slapd_daemon_init(char *urls, int port, int tls_port )
*/
if( (sel_exit_fd = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 )
{
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: socket() failed errno=%d (%s)\n", err,
errstr, 0 );
sock_errstr(err), 0 );
return sel_exit_fd;
} else {
struct sockaddr_in si;
int len = sizeof(si);
int err;
(void) memset( (void*) &si, 0, len );
......@@ -415,25 +412,25 @@ int slapd_daemon_init(char *urls, int port, int tls_port )
if( rc = bind( sel_exit_fd, (struct sockaddr *)&si, len ) )
{
SOCK_ERR(err, errstr);
err = sock_errno();
Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
(long) sel_exit_fd, err, errstr );
(long) sel_exit_fd, err, sock_errstr(err) );
tcp_close( sel_exit_fd );
return rc;
}
if( rc = getsockname( sel_exit_fd, (struct sockaddr *)&si, &len))
{
SOCK_ERR(err, errstr);
err = sock_errno();
Debug( LDAP_DEBUG_ANY, "daemon: getsockname(%ld) failed errno=%d (%s)\n",
(long) sel_exit_fd, err, errstr );
(long) sel_exit_fd, err, sock_errstr(err) );
tcp_close( sel_exit_fd );
return rc;
}
if( rc = connect( sel_exit_fd, (struct sockaddr *)&si, len))
{
SOCK_ERR(err, errstr);
err = sock_errno();
Debug( LDAP_DEBUG_ANY, "daemon: connect(%ld) failed errno=%d (%s)\n",
(long) sel_exit_fd, err, errstr );
(long) sel_exit_fd, err, sock_errstr(err) );
tcp_close( sel_exit_fd );
return rc;
}
......@@ -506,8 +503,6 @@ slapd_daemon_task(
)
{
int l;
int err;
char *errstr;
time( &starttime );
......@@ -516,11 +511,11 @@ slapd_daemon_task(
continue;
if ( listen( slap_listeners[l]->sl_sd, 5 ) == -1 ) {
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
(long) slap_listeners[l]->sl_url, err,
errstr );
sock_errstr(err) );
return( (void*)-1 );
}
......@@ -631,7 +626,8 @@ slapd_daemon_task(
NULL, tvp ))
{
case -1: { /* failure - try again */
SOCK_ERR(err, errstr);
int err = sock_errno();
if( err == EBADF && ++ebadf < SLAPD_EBADF_LIMIT) {
continue;
}
......@@ -639,7 +635,7 @@ slapd_daemon_task(
if( err != EINTR ) {
Debug( LDAP_DEBUG_CONNS,
"daemon: select failed (%d): %s\n",
err, errstr, 0 );
err, sock_errstr(err), 0 );
slapd_shutdown = -1;
}
......@@ -685,11 +681,11 @@ slapd_daemon_task(
if ( (s = accept( slap_listeners[l]->sl_sd,
(struct sockaddr *) &from, &len )) == AC_SOCKET_INVALID )
{
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: accept(%ld) failed errno=%d (%s)\n",
(long) slap_listeners[l]->sl_sd, err,
errstr );
sock_errstr(err) );
continue;
}
......@@ -722,10 +718,10 @@ slapd_daemon_task(
len = sizeof(from);
if ( getpeername( s, (struct sockaddr *) &from, &len ) != 0 ) {
SOCK_ERR(err, errstr);
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: getpeername( %ld ) failed: errno=%d (%s)\n",
(long) s, err, errstr );
(long) s, err, sock_errstr(err) );
slapd_close(s);
continue;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment