-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 2.1 2002/12/30 19:56:16 david__schmidt Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.35.2.8 2006/01/21 16:16:08 david__schmidt Exp $";
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/src/jbsockets.c,v $
+ * File : $Source: /cvsroot/ijbswa/current/Attic/jbsockets.c,v $
*
* Purpose : Contains wrappers for system-specific sockets code,
* so that the rest of Junkbuster can be more
*
* Revisions :
* $Log: jbsockets.c,v $
- * Revision 2.1 2002/12/30 19:56:16 david__schmidt
- * End of initial drop of statistics console infrastructure. Data stream
- * is transmitted on the stats port every interval, provided the data has
- * changed since the last transmission. More work probably needs to be
- * done with regard to multiplatform threading; I stole the thread spawning
- * code from jcc.c, but haven't been able to test it everywhere.
+ * Revision 1.35.2.8 2006/01/21 16:16:08 david__schmidt
+ * Thanks to Edward Carrel for his patch to modernize OSX's\rpthreads support. See bug #1409623.
*
- * Revision 2.0 2002/06/04 14:34:21 jongfoster
- * Moving source files to src/
+ * Revision 1.35.2.7 2005/05/07 21:50:55 david__schmidt
+ * A few memory leaks plugged (mostly on error paths)
*
- * Revision 1.36 2002/05/26 23:23:10 joergs
- * AmigaOS: Fixed wrong type for len in write_socket()
+ * Revision 1.35.2.6 2003/12/17 16:34:40 oes
+ * Cosmetics
+ *
+ * Revision 1.35.2.5 2003/04/29 11:32:54 oes
+ * Don't rely on h_addr being non-NULL after gethostbyname.
+ * Works around an oddness in Max OSX and closes bug #724796
+ *
+ * Revision 1.35.2.4 2003/04/04 12:40:20 oes
+ * Made sure the errno set by bind, not close[socket] is used in
+ * bind_port. Probably fixes bugs #713777, #705562.
+ *
+ * Revision 1.35.2.3 2003/03/07 03:41:04 david__schmidt
+ * Wrapping all *_r functions (the non-_r versions of them) with mutex semaphores for OSX. Hopefully this will take care of all of those pesky crash reports.
+ *
+ * Revision 1.35.2.2 2002/11/20 14:37:24 oes
+ * Fixed Win32 error logging in bind_port.
+ * Thanks to Oliver Stoeneberg for the hint.
+ *
+ * Revision 1.35.2.1 2002/05/26 23:41:27 joergs
+ * AmigaOS: Fixed wrong type of len in write_socket()
*
* Revision 1.35 2002/04/26 15:50:04 joergs
* AmigaOS: No socklen_t, added AMIGA to the systems using int instead.
#endif
+#include "project.h"
+
#ifdef OSX_DARWIN
#include <pthread.h>
#include "jcc.h"
/* jcc.h is for mutex semaphores only */
#endif /* def OSX_DARWIN */
-#include "project.h"
#include "jbsockets.h"
#include "filters.h"
#include "errlog.h"
if ((addr = resolve_hostname_to_ip(host)) == INADDR_NONE)
{
- if (csp)
- {
- csp->http->host_ip_addr_str = strdup("unknown");
- }
+ csp->http->host_ip_addr_str = strdup("unknown");
return(JB_INVALID_SOCKET);
}
#ifdef FEATURE_ACL
- if (csp)
- {
- dst->addr = ntohl((unsigned long) addr);
- dst->port = portnum;
+ dst->addr = ntohl((unsigned long) addr);
+ dst->port = portnum;
- if (block_acl(dst, csp))
- {
+ if (block_acl(dst, csp))
+ {
#ifdef __OS2__
- errno = SOCEPERM;
+ errno = SOCEPERM;
#else
- errno = EPERM;
+ errno = EPERM;
#endif
- return(JB_INVALID_SOCKET);
- }
+ return(JB_INVALID_SOCKET);
}
#endif /* def FEATURE_ACL */
inaddr.sin_addr.s_addr = addr;
inaddr.sin_family = AF_INET;
- if (csp)
- {
- csp->http->host_ip_addr_str = strdup(inet_ntoa(inaddr.sin_addr));
- }
+ csp->http->host_ip_addr_str = strdup(inet_ntoa(inaddr.sin_addr));
+
#ifndef _WIN32
if (sizeof(inaddr.sin_port) == sizeof(short))
#endif /* ndef _WIN32 */
#ifdef TCP_NODELAY
{ /* turn off TCP coalescence */
int mi = 1;
- setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &mi, sizeof (int));
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &mi, sizeof (int));
}
#endif /* def TCP_NODELAY */
return 0;
}
- if (len < 0)
+ if (len < 0) /* constant condition - size_t isn't ever negative */
{
return 1;
}
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
#endif /* ndef _WIN32 */
- if (bind (fd, (struct sockaddr *)&inaddr, sizeof(inaddr)) < 0)
+ if (bind(fd, (struct sockaddr *)&inaddr, sizeof(inaddr)) < 0)
{
- close_socket (fd);
#ifdef _WIN32
+ errno = WSAGetLastError();
if (errno == WSAEADDRINUSE)
#else
if (errno == EADDRINUSE)
#endif
{
+ close_socket(fd);
return(-3);
}
else
{
+ close_socket(fd);
return(-1);
}
}