1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 14:08:06 +01:00

- Added WMSetConnectionCloseOnExec() to specify if the socket of a

connection survives or not an exec* family call. By default all
  connections created by WINGs, set the socket to be closed on an exec*
  call. Use the function if you need the reverse.
This commit is contained in:
dan
2000-11-19 23:50:38 +00:00
parent 972620c7cd
commit 9d98d884ae
3 changed files with 43 additions and 16 deletions

View File

@@ -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:
............................

View File

@@ -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);

View File

@@ -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;
}
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;
}