mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-22 22:28:02 +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:
@@ -59,6 +59,15 @@ changes since wmaker 0.62.1:
|
|||||||
doesn't add "warning:" in the output message.
|
doesn't add "warning:" in the output message.
|
||||||
- added WMBox widget
|
- added WMBox widget
|
||||||
- added W_SetViewCursor()
|
- 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:
|
changes since wmaker 0.62.0:
|
||||||
............................
|
............................
|
||||||
|
|||||||
@@ -756,7 +756,9 @@ char* WMGetConnectionService(WMConnection *cPtr);
|
|||||||
|
|
||||||
char* WMGetConnectionProtocol(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);
|
void* WMGetConnectionClientData(WMConnection *cPtr);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
* TODO:
|
* TODO:
|
||||||
* - decide if we want to support connections with external sockets, else
|
* - decide if we want to support connections with external sockets, else
|
||||||
* clean up the structure of the unneeded members.
|
* 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);
|
state = fcntl(sock, F_GETFL, 0);
|
||||||
|
|
||||||
if (state < 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;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +273,7 @@ setSocketNonBlocking(int sock, Bool flag) /*FOLD00*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fcntl(sock, F_SETFL, state) < 0) {
|
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;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +361,8 @@ createConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/
|
|||||||
wretain(cPtr);
|
wretain(cPtr);
|
||||||
memset(cPtr, 0, sizeof(WMConnection));
|
memset(cPtr, 0, sizeof(WMConnection));
|
||||||
|
|
||||||
|
fcntl(sock, F_SETFD, FD_CLOEXEC); /* by default close on exec */
|
||||||
|
|
||||||
cPtr->sock = sock;
|
cPtr->sock = sock;
|
||||||
cPtr->openTimeout.timeout = OpenTimeout;
|
cPtr->openTimeout.timeout = OpenTimeout;
|
||||||
cPtr->openTimeout.handler = NULL;
|
cPtr->openTimeout.handler = NULL;
|
||||||
@@ -381,7 +384,7 @@ createConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/
|
|||||||
|
|
||||||
return cPtr;
|
return cPtr;
|
||||||
}
|
}
|
||||||
/*FOLD00*/
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
WMConnection*
|
WMConnection*
|
||||||
@@ -420,7 +423,7 @@ WMCreateConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/
|
|||||||
return cPtr;
|
return cPtr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*FOLD00*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* host is the name on which we want to listen for incoming connections,
|
* host is the name on which we want to listen for incoming connections,
|
||||||
@@ -672,11 +675,8 @@ WMAcceptConnection(WMConnection *listener) /*FOLD00*/
|
|||||||
int newSock;
|
int newSock;
|
||||||
WMConnection *newConnection;
|
WMConnection *newConnection;
|
||||||
|
|
||||||
if (listener->state!=WCListening) {
|
|
||||||
wwarning("Called 'WMAcceptConnection()' on a non-listening connection");
|
|
||||||
WCErrorCode = 0;
|
WCErrorCode = 0;
|
||||||
return NULL;
|
wassertrv(listener && listener->state==WCListening, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
size = sizeof(clientname);
|
size = sizeof(clientname);
|
||||||
newSock = accept(listener->sock, (struct sockaddr*) &clientname, &size);
|
newSock = accept(listener->sock, (struct sockaddr*) &clientname, &size);
|
||||||
@@ -918,7 +918,7 @@ WMIsConnectionNonBlocking(WMConnection *cPtr) /*FOLD00*/
|
|||||||
state = fcntl(cPtr->sock, F_GETFL, 0);
|
state = fcntl(cPtr->sock, F_GETFL, 0);
|
||||||
|
|
||||||
if (state < 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
|
/* 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
|
* not use fcntl to set non-blocking mode, and since a socket defaults
|
||||||
* to blocking when created, return False as the best assumption */
|
* to blocking when created, return False as the best assumption */
|
||||||
@@ -933,17 +933,33 @@ WMIsConnectionNonBlocking(WMConnection *cPtr) /*FOLD00*/
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
Bool
|
||||||
WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag) /*FOLD00*/
|
WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag) /*FOLD00*/
|
||||||
{
|
{
|
||||||
if (cPtr->sock < 0)
|
wassertrv(cPtr!=NULL && cPtr->sock>=0, False);
|
||||||
return;
|
|
||||||
|
|
||||||
if (cPtr->isNonBlocking == flag)
|
if (cPtr->isNonBlocking == flag)
|
||||||
return;
|
return True;
|
||||||
|
|
||||||
if (setSocketNonBlocking(cPtr->sock, flag)==True)
|
if (setSocketNonBlocking(cPtr->sock, flag)==True) {
|
||||||
cPtr->isNonBlocking = flag;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user