diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 19d9a9e8..79c6a503 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -59,6 +59,15 @@ changes since wmaker 0.62.1: doesn't add "warning:" in the output message. - added WMBox widget - added W_SetViewCursor() +- added WMGetConnectionUnsentData() (WMGetConnectionQueuedData() too as an + alias). +- added WMSetConnectionCloseOnExec() to specify if the socket associated + with a connection survives an exec* call or not. When a new connection is + created using the WMCreate... or WMAcceptConnection() calls, it has the + close on exec flag set automatically to 'True' by the library. Unless + you want to let the socket of some connection to survive across an exec* + call, you need not to call this function. + changes since wmaker 0.62.0: ............................ diff --git a/WINGs/WUtil.h b/WINGs/WUtil.h index 4d751806..742113fa 100644 --- a/WINGs/WUtil.h +++ b/WINGs/WUtil.h @@ -756,7 +756,9 @@ char* WMGetConnectionService(WMConnection *cPtr); char* WMGetConnectionProtocol(WMConnection *cPtr); -void WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag); +Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag); + +Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag); void* WMGetConnectionClientData(WMConnection *cPtr); diff --git a/WINGs/connection.c b/WINGs/connection.c index 49632433..aaaa9a58 100644 --- a/WINGs/connection.c +++ b/WINGs/connection.c @@ -23,6 +23,7 @@ * TODO: * - decide if we want to support connections with external sockets, else * clean up the structure of the unneeded members. + * - decide what to do with all wsyserror() and wwarning() calls. * */ @@ -255,7 +256,7 @@ setSocketNonBlocking(int sock, Bool flag) /*FOLD00*/ state = fcntl(sock, F_GETFL, 0); if (state < 0) { - wsyserror("Failed to get socket flags with fcntl."); + /*wsyserror("Failed to get socket flags with fcntl."); should we do this? -Dan*/ return False; } @@ -272,7 +273,7 @@ setSocketNonBlocking(int sock, Bool flag) /*FOLD00*/ } if (fcntl(sock, F_SETFL, state) < 0) { - wsyserror("Failed to set socket flags with fcntl."); + /*wsyserror("Failed to set socket flags with fcntl."); should we do this? -Dan */ return False; } @@ -360,6 +361,8 @@ createConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/ wretain(cPtr); memset(cPtr, 0, sizeof(WMConnection)); + fcntl(sock, F_SETFD, FD_CLOEXEC); /* by default close on exec */ + cPtr->sock = sock; cPtr->openTimeout.timeout = OpenTimeout; cPtr->openTimeout.handler = NULL; @@ -381,7 +384,7 @@ createConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/ return cPtr; } - /*FOLD00*/ + #if 0 WMConnection* @@ -420,7 +423,7 @@ WMCreateConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/ return cPtr; } #endif - /*FOLD00*/ + /* * host is the name on which we want to listen for incoming connections, @@ -672,11 +675,8 @@ WMAcceptConnection(WMConnection *listener) /*FOLD00*/ int newSock; WMConnection *newConnection; - if (listener->state!=WCListening) { - wwarning("Called 'WMAcceptConnection()' on a non-listening connection"); - WCErrorCode = 0; - return NULL; - } + WCErrorCode = 0; + wassertrv(listener && listener->state==WCListening, NULL); size = sizeof(clientname); newSock = accept(listener->sock, (struct sockaddr*) &clientname, &size); @@ -918,7 +918,7 @@ WMIsConnectionNonBlocking(WMConnection *cPtr) /*FOLD00*/ state = fcntl(cPtr->sock, F_GETFL, 0); if (state < 0) { - wsyserror("Failed to get socket flags with fcntl."); + /*wsyserror("Failed to get socket flags with fcntl.");*/ /* If we can't use fcntl on socket, this probably also means we could * not use fcntl to set non-blocking mode, and since a socket defaults * to blocking when created, return False as the best assumption */ @@ -933,17 +933,33 @@ WMIsConnectionNonBlocking(WMConnection *cPtr) /*FOLD00*/ #endif -void +Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag) /*FOLD00*/ { - if (cPtr->sock < 0) - return; + wassertrv(cPtr!=NULL && cPtr->sock>=0, False); if (cPtr->isNonBlocking == flag) - return; + return True; - if (setSocketNonBlocking(cPtr->sock, flag)==True) + if (setSocketNonBlocking(cPtr->sock, flag)==True) { cPtr->isNonBlocking = flag; + return True; + } + + return False; +} + + +Bool +WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag) +{ + wassertrv(cPtr!=NULL && cPtr->sock>=0, False); + + if (fcntl(cPtr->sock, F_SETFD, (flag ? FD_CLOEXEC : 0)) < 0) { + return False; + } + + return True; }