Changeset: bef4ac95250b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bef4ac95250b
Modified Files:
MonetDB/src/common/stream.mx
MonetDB4/src/mapi/mapi.mx
MonetDB4/src/modules/plain/tcpip.mx
MonetDB5/src/modules/mal/mal_mapi.mx
clients/src/mapilib/Mapi.mx
pathfinder/runtime/shttpd.c
pathfinder/runtime/shttpd.h
pathfinder/runtime/xrpc_client.mx
pathfinder/runtime/xrpc_server.mx
Branch: Jun2010
Log Message:
On Windows you *must* use the SOCKET type and closesocket for sockets.
Also get rid of ancient setsockopt calls that are no longer supported
in winsock2 (which we must use for getaddrinfo).
diffs (298 lines):
diff -r 1fe68d092235 -r bef4ac95250b MonetDB/src/common/stream.mx
--- a/MonetDB/src/common/stream.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/MonetDB/src/common/stream.mx Fri Jul 23 18:02:36 2010 +0200
@@ -380,16 +380,10 @@
#ifdef NATIVE_WIN32
{
- int sockopt = SO_SYNCHRONOUS_NONALERT;
WSADATA w;
if (WSAStartup(0x0101, &w) != 0)
return -1;
-
- if (setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (void
*) &sockopt, sizeof(sockopt)) < 0) {
- WSACleanup();
- return -1;
- }
}
#endif
inited = 1;
diff -r 1fe68d092235 -r bef4ac95250b MonetDB4/src/mapi/mapi.mx
--- a/MonetDB4/src/mapi/mapi.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/MonetDB4/src/mapi/mapi.mx Fri Jul 23 18:02:36 2010 +0200
@@ -747,7 +747,7 @@
#ifdef HAVE_SYS_UN_H
struct sockaddr_un userver;
- SOCKET usock = -1;
+ SOCKET usock = INVALID_SOCKET;
#endif
char *usockfile;
socklen_t length = 0;
@@ -859,7 +859,7 @@
if (sock != INVALID_SOCKET)
FD_SET(sock, &fds);
#ifdef HAVE_SYS_UN_H
- if (usock >= 0)
+ if (usock != INVALID_SOCKET)
FD_SET(usock, &fds);
#endif
/* Wait up to 2 seconds. */
diff -r 1fe68d092235 -r bef4ac95250b MonetDB4/src/modules/plain/tcpip.mx
--- a/MonetDB4/src/modules/plain/tcpip.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/MonetDB4/src/modules/plain/tcpip.mx Fri Jul 23 18:02:36 2010 +0200
@@ -1222,7 +1222,7 @@
TCPlisten(int *port)
{
struct sockaddr_in server, client;
- SOCKET msgsock = -1;
+ SOCKET msgsock = INVALID_SOCKET;
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
int port_no = 0, i, on = 1;
SOCKLEN server_len = (SOCKLEN) sizeof(server);
diff -r 1fe68d092235 -r bef4ac95250b MonetDB5/src/modules/mal/mal_mapi.mx
--- a/MonetDB5/src/modules/mal/mal_mapi.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/MonetDB5/src/modules/mal/mal_mapi.mx Fri Jul 23 18:02:36 2010 +0200
@@ -554,7 +554,7 @@
rv = recvmsg(msgsock, &msgh, 0);
if (rv == -1) {
- close(msgsock);
+ closesocket(msgsock);
continue;
}
@@ -566,18 +566,18 @@
/* filedescriptor, put it in place of
msgsock */
cmsg = CMSG_FIRSTHDR(&msgh);
if (!cmsg->cmsg_type == SCM_RIGHTS) {
- close(msgsock);
+ closesocket(msgsock);
fprintf(stderr,
"!mal_mapi.listen: "
"expected
filedescriptor, but "
"received
something else\n");
continue;
}
- close(msgsock);
+ closesocket(msgsock);
msgsock = *(int*)CMSG_DATA(cmsg);
break;
default:
/* some unknown state */
- close(msgsock);
+ closesocket(msgsock);
fprintf(stderr, "!mal_mapi.listen: "
"unknown command type
in first byte\n");
continue;
diff -r 1fe68d092235 -r bef4ac95250b clients/src/mapilib/Mapi.mx
--- a/clients/src/mapilib/Mapi.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/clients/src/mapilib/Mapi.mx Fri Jul 23 18:02:36 2010 +0200
@@ -2385,7 +2385,7 @@
msg.msg_flags = 0;
if (sendmsg(s, &msg, 0) < 0) {
- close(s);
+ closesocket(s);
snprintf(errbuf, sizeof(errbuf), "could not send
initial byte: %s", strerror(errno));
return mapi_setError(mid, errbuf, "mapi_reconnect",
MERROR);
}
@@ -2416,7 +2416,7 @@
continue;
if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
break; /* success */
- close(s);
+ closesocket(s);
}
freeaddrinfo(res);
if (rp == NULL)
diff -r 1fe68d092235 -r bef4ac95250b pathfinder/runtime/shttpd.c
--- a/pathfinder/runtime/shttpd.c Fri Jul 23 17:59:23 2010 +0200
+++ b/pathfinder/runtime/shttpd.c Fri Jul 23 18:02:36 2010 +0200
@@ -3121,11 +3121,7 @@
/* Initialize winsock library */
{
WSADATA data;
- int opt = SO_SYNCHRONOUS_NONALERT;
WSAStartup(MAKEWORD(2,2), &data);
- if (setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
- (void *)&opt,sizeof(opt)) < 0)
- elog(ERR_FATAL, "setsockopt: %d", ERRNO);
}
#endif /* _WIN32 */
diff -r 1fe68d092235 -r bef4ac95250b pathfinder/runtime/shttpd.h
--- a/pathfinder/runtime/shttpd.h Fri Jul 23 17:59:23 2010 +0200
+++ b/pathfinder/runtime/shttpd.h Fri Jul 23 18:02:36 2010 +0200
@@ -57,7 +57,7 @@
* this structure keeps all per-socket global information.
*/
typedef struct {
- int sock;
+ SOCKET sock;
unsigned int nrequests; /* Requests made */
unsigned int kb_in, kb_out; /* IN/OUT traffic counters */
struct conn *connections; /* List of connections */
diff -r 1fe68d092235 -r bef4ac95250b pathfinder/runtime/xrpc_client.mx
--- a/pathfinder/runtime/xrpc_client.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/pathfinder/runtime/xrpc_client.mx Fri Jul 23 18:02:36 2010 +0200
@@ -542,13 +542,14 @@
*
* Returns: a socket number if succeeded, -1 otherwise.
*/
-static int
+static SOCKET
setup_connection(str dst, int *port)
{
struct in_addr addr;
struct sockaddr_in sockaddr;
struct hostent *resolv = NULL;
- int i, ret, sock = -1, p = 0;
+ int i, p = 0;
+ SOCKET ret, sock = INVALID_SOCKET;
str strptr = NULL;
/* remove whitespace characters at the beginning and the end of the
@@ -572,13 +573,13 @@
p = strtol(strptr, (char **)NULL, 10);
if (p <= 0) {
GDKerror("setup_connection: invalid port number: %s\n", strptr);
- return -1;
+ return INVALID_SOCKET;
}
} else { /* find the default port number from "monet_environment" */
if( !(strptr = GDKgetenv("xrpc_port")) || !(*strptr) ){
if( !(strptr = GDKgetenv("mapi_port")) ){
GDKerror("setup_connection: could not find \"mapi_port\"\n");
- return -1;
+ return INVALID_SOCKET;
}
p = atoi(strptr) + 1;
} else {
@@ -589,13 +590,13 @@
if (isdigit((int) (unsigned char) dst[0])) {
if ((i = inet_addr(dst)) < 0) {
GDKerror("setup_connection: invalid IP address \"%s\"\n", dst);
- return -1;
+ return INVALID_SOCKET;
}
addr.s_addr = (unsigned) i;
} else {
if (!(resolv = gethostbyname(dst))) {
GDKerror("setup_connection: invalid IP address \"%s\"\n", dst);
- return -1;
+ return INVALID_SOCKET;
}
addr.s_addr = ((struct in_addr *)resolv->h_addr_list[0])->s_addr;
}
@@ -605,18 +606,18 @@
sockaddr.sin_addr.s_addr = addr.s_addr;
memset(&(sockaddr.sin_zero), '\0', 8);
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET) {
GDKerror("setup_connection: failed to create socket\n");
- return -1;
+ return INVALID_SOCKET;
}
ret = connect(sock, (struct sockaddr *) &sockaddr, sizeof(sockaddr));
- for (i = NR_RETRIES; i > 0 && ret < 0; i--) {
+ for (i = NR_RETRIES; i > 0 && ret == INVALID_SOCKET; i--) {
MT_sleep_ms(1);
ret = connect(sock, (struct sockaddr *) &sockaddr, sizeof(sockaddr));
}
- if (ret < 0) {
+ if (ret == INVALID_SOCKET) {
GDKerror("setup_connection: failed to setup connection with %s:%d\n",
dst, p);
closesocket(sock);
return INVALID_SOCKET;
@@ -1188,7 +1189,8 @@
BAT *dec_values,
BAT *str_values)
{
- int sock = -1, port = -1;
+ int port = -1;
+ SOCKET sock = INVALID_SOCKET;
stream *in = NULL, *out = NULL;
buffer *req = NULL;
size_t bytes_sent = 0;
@@ -1211,7 +1213,7 @@
return GDK_FAIL;
if (!(out = socket_wastream(sock, "http_send"))) {
GDKerror("do_simple_query: failed to create socket_wastream for
sending XRPC request\n");
- close(sock);
+ closesocket(sock);
return GDK_FAIL;
}
@@ -1239,7 +1241,7 @@
GDKerror("do_simple_query: failed to send XRPC request.");
stream_close(out); stream_destroy(out);
buffer_destroy(req);
- close(sock);
+ closesocket(sock);
return GDK_FAIL;
}
/* Stop timing Network Send Client2Server */
@@ -1271,7 +1273,7 @@
/* send a WSAT request */
static int
-xrpc_2pc_send(int sock, char* dst, int port, str msg) {
+xrpc_2pc_send(SOCKET sock, char* dst, int port, str msg) {
stream *out = NULL;
if (!(out = socket_wastream(sock, "http_send"))) {
@@ -1301,7 +1303,7 @@
/* get a WSAT response */
static int
-xrpc_2pc_recv(int sock, char* dst, int port, str msg) {
+xrpc_2pc_recv(SOCKET sock, char* dst, int port, str msg) {
stream *in = NULL;
BAT* shredBAT;
int ret = GDK_FAIL;
@@ -1330,7 +1332,7 @@
int i, j, ret=GDK_FAIL, cnt=0, npart = BATcount(participants);
str *part = (str*) alloca(npart*sizeof(npart));
int *port = (int*) alloca(npart*sizeof(int));
- int *sock = (int*) alloca(npart*sizeof(int)), xrpc_updating;
+ SOCKET *sock = (SOCKET*) alloca(npart*sizeof(SOCKET)), xrpc_updating;
char dst[1024], msg[1024], *r;
BATiter pi = bat_iterator(participants);
BUN p,q;
@@ -1376,7 +1378,7 @@
cleanup:
for(i=0; i<cnt; i++) {
if (part[i]) GDKfree(part[i]);
- if (sock[i] >= 0) close(sock[i]);
+ if (sock[i] != INVALID_SOCKET) closesocket(sock[i]);
}
return ret;
}
diff -r 1fe68d092235 -r bef4ac95250b pathfinder/runtime/xrpc_server.mx
--- a/pathfinder/runtime/xrpc_server.mx Fri Jul 23 17:59:23 2010 +0200
+++ b/pathfinder/runtime/xrpc_server.mx Fri Jul 23 18:02:36 2010 +0200
@@ -186,7 +186,7 @@
static int rpcd_running = 0;
static int timing = 0;
static int debug = 0;
-static int listen_socket = -1;
+static SOCKET listen_socket = INVALID_SOCKET;
typedef struct {
lng start;
@@ -924,8 +924,8 @@
{
shttpd_fini(); /* Shut down the HTTP server. */
rpcd_running = 0; /* Stop RPC server */
- if (listen_socket >= 0)
- close(listen_socket);
- listen_socket = -1;
+ if (listen_socket != INVALID_SOCKET)
+ closesocket(listen_socket);
+ listen_socket = INVALID_SOCKET;
}
/* vim:set shiftwidth=4 expandtab: */
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list