2 * WINGs WMConnection function library
4 * Copyright (c) 1999-2000 Dan Pascu
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * - decide if we want to support connections with external sockets, else
25 * clean up the structure of the unneeded members.
26 * - decide what to do with all wwarning() calls that are still there.
31 #include "../src/config.h"
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
47 #include <sys/signal.h>
53 /* Some older systems does not define this (linux libc5, maybe others too) */
65 # define INADDR_NONE -1
68 /* Stuff for setting the sockets into non-blocking mode. */
69 /*#ifdef __POSIX_SOURCE
70 # define NONBLOCK_OPT O_NONBLOCK
72 # define NONBLOCK_OPT FNDELAY
75 #define NONBLOCK_OPT O_NONBLOCK
77 #define NETBUF_SIZE 4096
79 #define DEF_TIMEOUT 600 /* 600 seconds == 10 minutes */
85 static Bool SigInitialized
= False
;
87 static unsigned int DefaultTimeout
= DEF_TIMEOUT
;
88 static unsigned int OpenTimeout
= DEF_TIMEOUT
;
92 typedef struct TimeoutData
{
98 typedef struct W_Connection
{
99 int sock
; /* the socket we speak through */
102 WMHandlerID
*read
; /* the input read handler */
103 WMHandlerID
*write
; /* the input write handler */
104 WMHandlerID
*exception
; /* the input exception handler */
107 ConnectionDelegate
*delegate
; /* client delegates */
108 void *clientData
; /* client data */
109 unsigned int uflags
; /* flags for the client */
111 WMArray
*outputQueue
;
114 TimeoutData sendTimeout
;
115 TimeoutData openTimeout
;
117 WMConnectionState state
;
118 WMConnectionTimeoutState timeoutState
;
133 clearOutputQueue(WMConnection
*cPtr
) /*FOLD00*/
136 WMEmptyArray(cPtr
->outputQueue
);
141 openTimeout(void *cdata
) /*FOLD00*/
143 WMConnection
*cPtr
= (WMConnection
*) cdata
;
145 cPtr
->openTimeout
.handler
= NULL
;
146 if (cPtr
->handler
.write
) {
147 WMDeleteInputHandler(cPtr
->handler
.write
);
148 cPtr
->handler
.write
= NULL
;
150 if (cPtr
->state
!= WCConnected
) {
151 cPtr
->state
= WCTimedOut
;
152 cPtr
->timeoutState
= WCTWhileOpening
;
153 if (cPtr
->delegate
&& cPtr
->delegate
->didTimeout
) {
154 (*cPtr
->delegate
->didTimeout
)(cPtr
->delegate
, cPtr
);
156 WMCloseConnection(cPtr
);
157 cPtr
->state
= WCTimedOut
; /* the above set state to WCClosed */
164 sendTimeout(void *cdata
) /*FOLD00*/
166 WMConnection
*cPtr
= (WMConnection
*) cdata
;
168 cPtr
->sendTimeout
.handler
= NULL
;
169 if (cPtr
->handler
.write
) {
170 WMDeleteInputHandler(cPtr
->handler
.write
);
171 cPtr
->handler
.write
= NULL
;
173 if (WMGetArrayItemCount(cPtr
->outputQueue
)>0) {
174 clearOutputQueue(cPtr
);
175 cPtr
->state
= WCTimedOut
;
176 cPtr
->timeoutState
= WCTWhileSending
;
177 if (cPtr
->delegate
&& cPtr
->delegate
->didTimeout
) {
178 (*cPtr
->delegate
->didTimeout
)(cPtr
->delegate
, cPtr
);
180 WMCloseConnection(cPtr
);
181 cPtr
->state
= WCTimedOut
; /* the above set state to WCClosed */
188 inputHandler(int fd
, int mask
, void *clientData
) /*FOLD00*/
190 WMConnection
*cPtr
= (WMConnection
*)clientData
;
192 if (cPtr
->state
==WCClosed
|| cPtr
->state
==WCDied
)
195 if ((mask
& WIWriteMask
)) {
196 if (cPtr
->state
== WCInProgress
) {
199 int len
= sizeof(result
);
202 if (getsockopt(cPtr
->sock
, SOL_SOCKET
, SO_ERROR
,
203 (void*)&result
, &len
) == 0 && result
!= 0) {
204 cPtr
->state
= WCFailed
;
205 WCErrorCode
= result
;
207 /* should call wsyserrorwithcode(result, ...) here? */
209 cPtr
->state
= WCConnected
;
213 if (cPtr
->handler
.write
) {
214 WMDeleteInputHandler(cPtr
->handler
.write
);
215 cPtr
->handler
.write
= NULL
;
218 if (cPtr
->openTimeout
.handler
) {
219 WMDeleteTimerHandler(cPtr
->openTimeout
.handler
);
220 cPtr
->openTimeout
.handler
= NULL
;
223 if (cPtr
->delegate
&& cPtr
->delegate
->didInitialize
)
224 (*cPtr
->delegate
->didInitialize
)(cPtr
->delegate
, cPtr
);
226 /* we use failed and not cPtr->state here, because cPtr may be
227 * destroyed by the delegate called above if the connection failed
231 } else if (cPtr
->state
== WCConnected
) {
232 WMFlushConnection(cPtr
);
239 /* if the connection died, may get destroyed in the delegate, so retain */
242 if ((mask
& WIReadMask
) && cPtr
->delegate
->didReceiveInput
)
243 (*cPtr
->delegate
->didReceiveInput
)(cPtr
->delegate
, cPtr
);
245 if ((mask
& WIExceptMask
) && cPtr
->delegate
->didCatchException
)
246 (*cPtr
->delegate
->didCatchException
)(cPtr
->delegate
, cPtr
);
253 setSocketNonBlocking(int sock
, Bool flag
) /*FOLD00*/
258 state
= fcntl(sock
, F_GETFL
, 0);
261 /* set WCErrorCode here? -Dan*/
265 isNonBlock
= (state
& NONBLOCK_OPT
) != 0;
270 state
|= NONBLOCK_OPT
;
274 state
&= ~NONBLOCK_OPT
;
277 if (fcntl(sock
, F_SETFL
, state
) < 0) {
278 /* set WCErrorCode here? -Dan*/
287 setConnectionAddress(WMConnection
*cPtr
, struct sockaddr_in
*socketaddr
) /*FOLD00*/
289 wassertr(cPtr
->address
==NULL
);
291 cPtr
->address
= wstrdup(inet_ntoa(socketaddr
->sin_addr
));
292 cPtr
->service
= wmalloc(16);
293 sprintf(cPtr
->service
, "%hu", ntohs(socketaddr
->sin_port
));
294 cPtr
->protocol
= wstrdup("tcp");
298 static struct sockaddr_in
*
299 getSocketAddress(char* name
, char* service
, char* protocol
) /*FOLD00*/
301 static struct sockaddr_in socketaddr
;
304 if (!protocol
|| protocol
[0]==0)
307 memset(&socketaddr
, 0, sizeof(struct sockaddr_in
));
308 socketaddr
.sin_family
= AF_INET
;
311 * If we were given a hostname, we use any address for that host.
312 * Otherwise we expect the given name to be an address unless it is
313 * NULL (any address).
315 if (name
&& name
[0]!=0) {
316 WMHost
*host
= WMGetHostWithName(name
);
319 return NULL
; /* name is not a hostname nor a number and dot adr */
321 name
= WMGetHostAddress(host
);
322 #ifndef HAVE_INET_ATON
323 if ((socketaddr
.sin_addr
.s_addr
= inet_addr(name
)) == INADDR_NONE
) {
325 if (inet_aton(name
, &socketaddr
.sin_addr
) == 0) {
332 socketaddr
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
335 if (!service
|| service
[0]==0) {
336 socketaddr
.sin_port
= 0;
337 } else if ((sp
= getservbyname(service
, protocol
))==0) {
341 portNumber
= strtoul(service
, &endptr
, 10);
343 if (service
[0]!=0 && *endptr
==0 && portNumber
<65536) {
344 socketaddr
.sin_port
= htons(portNumber
);
349 socketaddr
.sin_port
= sp
->s_port
;
357 dummyHandler(int signum
)
363 createConnectionWithSocket(int sock
, Bool closeOnRelease
) /*FOLD00*/
366 struct sigaction sig_action
;
368 cPtr
= wmalloc(sizeof(WMConnection
));
370 memset(cPtr
, 0, sizeof(WMConnection
));
372 fcntl(sock
, F_SETFD
, FD_CLOEXEC
); /* by default close on exec */
375 cPtr
->openTimeout
.timeout
= OpenTimeout
;
376 cPtr
->openTimeout
.handler
= NULL
;
377 cPtr
->sendTimeout
.timeout
= DefaultTimeout
;
378 cPtr
->sendTimeout
.handler
= NULL
;
379 cPtr
->closeOnRelease
= closeOnRelease
;
381 WMCreateArrayWithDestructor(16, (WMFreeDataProc
*)WMReleaseData
);
382 cPtr
->state
= WCNotConnected
;
383 cPtr
->timeoutState
= WCTNone
;
385 /* ignore dead pipe */
386 if (!SigInitialized
) {
387 /* Because POSIX mandates that only signal with handlers are reset
388 * accross an exec*(), we do not want to propagate ignoring SIGPIPEs
389 * to children. Hence the dummy handler. Philippe Troin <phil@fifi.org>
391 sig_action
.sa_handler
= &dummyHandler
;
392 sig_action
.sa_flags
= SA_RESTART
;
393 sigaction(SIGPIPE
, &sig_action
, NULL
);
394 SigInitialized
= True
;
403 WMCreateConnectionWithSocket(int sock
, Bool closeOnRelease
) /*FOLD00*/
406 struct sockaddr_in clientname
;
410 cPtr
= createConnectionWithSocket(sock
, closeOnRelease
);
411 cPtr
->wasNonBlocking
= WMIsConnectionNonBlocking(cPtr
);
412 cPtr
->isNonBlocking
= cPtr
->wasNonBlocking
;
414 /* some way to find out if it is connected, and binded. can't find
415 if it listens though!!!
418 size
= sizeof(clientname
);
419 n
= getpeername(sock
, (struct sockaddr
*) &clientname
, &size
);
421 /* Since we have a peer, it means we are connected */
422 cPtr
->state
= WCConnected
;
424 size
= sizeof(clientname
);
425 n
= getsockname(sock
, (struct sockaddr
*) &clientname
, &size
);
427 /* We don't have a peer, but we are binded to an address.
428 * Assume we are listening on it (we don't know that for sure!)
430 cPtr
->state
= WCListening
;
432 cPtr
->state
= WCNotConnected
;
442 * host is the name on which we want to listen for incoming connections,
443 * and it must be a name of this host, or NULL if we want to listen
444 * on any incoming address.
445 * service is either a service name as present in /etc/services, or the port
446 * number we want to listen on. If NULL, a random port between
447 * 1024 and 65535 will be assigned to us.
448 * protocol is one of "tcp" or "udp". If NULL, "tcp" will be used by default.
449 * currently only "tcp" is supported.
452 WMCreateConnectionAsServerAtAddress(char *host
, char *service
, char *protocol
) /*FOLD00*/
455 struct sockaddr_in
*socketaddr
;
461 if ((socketaddr
= getSocketAddress(host
, service
, protocol
)) == NULL
) {
462 wwarning(_("Bad address-service-protocol combination"));
466 /* Create the actual socket */
467 sock
= socket(PF_INET
, SOCK_STREAM
, 0);
474 * Set socket options. We try to make the port reusable and have it
475 * close as fast as possible without waiting in unnecessary wait states
479 setsockopt(sock
, SOL_SOCKET
, SO_REUSEADDR
, (void *)&on
, sizeof(on
));
481 if (bind(sock
, (struct sockaddr
*)socketaddr
, sizeof(*socketaddr
)) < 0) {
487 if (listen(sock
, 10) < 0) {
493 /* Find out what is the address/service/protocol we get */
494 /* In case some of address/service/protocol were NULL */
495 size
= sizeof(*socketaddr
);
496 if (getsockname(sock
, (struct sockaddr
*)socketaddr
, &size
) < 0) {
502 cPtr
= createConnectionWithSocket(sock
, True
);
503 cPtr
->state
= WCListening
;
504 WMSetConnectionNonBlocking(cPtr
, True
);
506 setConnectionAddress(cPtr
, socketaddr
);
513 WMCreateConnectionToAddress(char *host
, char *service
, char *protocol
) /*FOLD00*/
516 struct sockaddr_in
*socketaddr
;
521 wassertrv(service
!=NULL
&& service
[0]!=0, NULL
);
523 if (host
==NULL
|| host
[0]==0)
526 if ((socketaddr
= getSocketAddress(host
, service
, protocol
)) == NULL
) {
527 wwarning(_("Bad address-service-protocol combination"));
531 /* Create the actual socket */
532 sock
= socket(PF_INET
, SOCK_STREAM
, 0);
537 /* make socket blocking while we connect. */
538 setSocketNonBlocking(sock
, False
);
539 if (connect(sock
, (struct sockaddr
*)socketaddr
, sizeof(*socketaddr
)) < 0) {
545 cPtr
= createConnectionWithSocket(sock
, True
);
546 cPtr
->state
= WCConnected
;
547 WMSetConnectionNonBlocking(cPtr
, True
);
548 setConnectionAddress(cPtr
, socketaddr
);
555 WMCreateConnectionToAddressAndNotify(char *host
, char *service
, char *protocol
) /*FOLD00*/
558 struct sockaddr_in
*socketaddr
;
564 wassertrv(service
!=NULL
&& service
[0]!=0, NULL
);
566 if (host
==NULL
|| host
[0]==0)
569 if ((socketaddr
= getSocketAddress(host
, service
, protocol
)) == NULL
) {
570 wwarning(_("Bad address-service-protocol combination"));
574 /* Create the actual socket */
575 sock
= socket(PF_INET
, SOCK_STREAM
, 0);
580 isNonBlocking
= setSocketNonBlocking(sock
, True
);
581 if (connect(sock
, (struct sockaddr
*)socketaddr
, sizeof(*socketaddr
)) < 0) {
582 if (errno
!=EINPROGRESS
) {
589 cPtr
= createConnectionWithSocket(sock
, True
);
590 cPtr
->state
= WCInProgress
;
591 cPtr
->isNonBlocking
= isNonBlocking
;
593 cPtr
->handler
.write
= WMAddInputHandler(cPtr
->sock
, WIWriteMask
,
596 cPtr
->openTimeout
.handler
=
597 WMAddTimerHandler(cPtr
->openTimeout
.timeout
*1000, openTimeout
, cPtr
);
599 setConnectionAddress(cPtr
, socketaddr
);
606 removeAllHandlers(WMConnection
*cPtr
) /*FOLD00*/
608 if (cPtr
->handler
.read
)
609 WMDeleteInputHandler(cPtr
->handler
.read
);
610 if (cPtr
->handler
.write
)
611 WMDeleteInputHandler(cPtr
->handler
.write
);
612 if (cPtr
->handler
.exception
)
613 WMDeleteInputHandler(cPtr
->handler
.exception
);
614 if (cPtr
->openTimeout
.handler
)
615 WMDeleteTimerHandler(cPtr
->openTimeout
.handler
);
616 if (cPtr
->sendTimeout
.handler
)
617 WMDeleteTimerHandler(cPtr
->sendTimeout
.handler
);
619 cPtr
->handler
.read
= NULL
;
620 cPtr
->handler
.write
= NULL
;
621 cPtr
->handler
.exception
= NULL
;
622 cPtr
->openTimeout
.handler
= NULL
;
623 cPtr
->sendTimeout
.handler
= NULL
;
628 WMDestroyConnection(WMConnection
*cPtr
) /*FOLD00*/
630 if (cPtr
->closeOnRelease
&& cPtr
->sock
>=0) {
631 shutdown(cPtr
->sock
, SHUT_RDWR
);
635 removeAllHandlers(cPtr
);
636 WMFreeArray(cPtr
->outputQueue
); /* will also free the items with the destructor */
639 wfree(cPtr
->address
);
640 wfree(cPtr
->service
);
641 wfree(cPtr
->protocol
);
649 WMCloseConnection(WMConnection
*cPtr
) /*FOLD00*/
652 shutdown(cPtr
->sock
, SHUT_RDWR
);
657 removeAllHandlers(cPtr
);
658 clearOutputQueue(cPtr
);
660 cPtr
->state
= WCClosed
;
665 WMAcceptConnection(WMConnection
*listener
) /*FOLD00*/
667 struct sockaddr_in clientname
;
670 WMConnection
*newConnection
;
673 wassertrv(listener
&& listener
->state
==WCListening
, NULL
);
675 size
= sizeof(clientname
);
676 newSock
= accept(listener
->sock
, (struct sockaddr
*) &clientname
, &size
);
678 WCErrorCode
= ((errno
!=EAGAIN
&& errno
!=EWOULDBLOCK
) ? errno
: 0);
682 newConnection
= createConnectionWithSocket(newSock
, True
);
683 WMSetConnectionNonBlocking(newConnection
, True
);
684 newConnection
->state
= WCConnected
;
685 setConnectionAddress(newConnection
, &clientname
);
687 return newConnection
;
692 WMGetConnectionAddress(WMConnection
*cPtr
) /*FOLD00*/
694 return cPtr
->address
;
699 WMGetConnectionService(WMConnection
*cPtr
) /*FOLD00*/
701 return cPtr
->service
;
706 WMGetConnectionProtocol(WMConnection
*cPtr
) /*FOLD00*/
708 return cPtr
->protocol
;
713 WMGetConnectionSocket(WMConnection
*cPtr
) /*FOLD00*/
720 WMGetConnectionState(WMConnection
*cPtr
) /*FOLD00*/
726 WMConnectionTimeoutState
727 WMGetConnectionTimeoutState(WMConnection
*cPtr
) /*FOLD00*/
729 return cPtr
->timeoutState
;
734 WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
) /*FOLD00*/
736 wassertrv(cPtr
->state
!=WCNotConnected
&& cPtr
->state
!=WCListening
, False
);
737 wassertrv(cPtr
->state
!=WCInProgress
&& cPtr
->state
!=WCFailed
, False
);
739 if (cPtr
->state
!=WCConnected
)
742 WMAddToArray(cPtr
->outputQueue
, WMRetainData(data
));
748 WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
) /*FOLD00*/
750 int bytes
, pos
, len
, totalTransfer
;
751 TimeoutData
*tPtr
= &cPtr
->sendTimeout
;
752 const unsigned char *dataBytes
;
754 wassertrv(cPtr
->state
!=WCNotConnected
&& cPtr
->state
!=WCListening
, -1);
755 wassertrv(cPtr
->state
!=WCInProgress
&& cPtr
->state
!=WCFailed
, -1);
757 if (cPtr
->state
!=WCConnected
)
760 /* If we have no data just flush the queue, else try to send data */
761 if (data
&& WMGetDataLength(data
)>0) {
762 WMAddToArray(cPtr
->outputQueue
, WMRetainData(data
));
763 /* If there already was something in queue, and also a write input
764 * handler is established, it means we were unable to send, so
765 * return and let the write handler notify us when we can send.
767 if (WMGetArrayItemCount(cPtr
->outputQueue
)>1 && cPtr
->handler
.write
)
773 while (WMGetArrayItemCount(cPtr
->outputQueue
) > 0) {
774 data
= WMGetFromArray(cPtr
->outputQueue
, 0);
775 dataBytes
= (const unsigned char *)WMDataBytes(data
);
776 len
= WMGetDataLength(data
);
777 pos
= cPtr
->bufPos
; /* where we're left last time */
780 bytes
= write(cPtr
->sock
, dataBytes
+pos
, len
- pos
);
786 /* save the position where we're left and add a timeout */
788 if (!tPtr
->handler
) {
789 tPtr
->handler
= WMAddTimerHandler(tPtr
->timeout
*1000,
792 if (!cPtr
->handler
.write
) {
793 cPtr
->handler
.write
=
794 WMAddInputHandler(cPtr
->sock
, WIWriteMask
,
797 return totalTransfer
;
800 cPtr
->state
= WCDied
;
801 removeAllHandlers(cPtr
);
802 if (cPtr
->delegate
&& cPtr
->delegate
->didDie
)
803 (*cPtr
->delegate
->didDie
)(cPtr
->delegate
, cPtr
);
808 totalTransfer
+= bytes
;
810 WMDeleteFromArray(cPtr
->outputQueue
, 0);
813 WMDeleteTimerHandler(tPtr
->handler
);
814 tPtr
->handler
= NULL
;
816 if (cPtr
->handler
.write
) {
817 WMDeleteInputHandler(cPtr
->handler
.write
);
818 cPtr
->handler
.write
= NULL
;
822 return totalTransfer
;
827 * WMGetConnectionAvailableData(connection):
829 * will return a WMData structure containing the available data on the
830 * specified connection. If connection is non-blocking (default) and no data
831 * is available when this function is called, an empty WMData is returned.
833 * If an error occurs while reading or the other side closed connection,
834 * it will return NULL.
835 * Also trying to read from an already died or closed connection is
836 * considered to be an error condition, and will return NULL.
839 WMGetConnectionAvailableData(WMConnection
*cPtr
) /*FOLD00*/
841 char buffer
[NETBUF_SIZE
];
845 wassertrv(cPtr
->state
!=WCNotConnected
&& cPtr
->state
!=WCListening
, NULL
);
846 wassertrv(cPtr
->state
!=WCInProgress
&& cPtr
->state
!=WCFailed
, NULL
);
848 if (cPtr
->state
!=WCConnected
)
854 nbytes
= read(cPtr
->sock
, buffer
, NETBUF_SIZE
);
860 aData
= WMCreateDataWithCapacity(0);
864 cPtr
->state
= WCDied
;
865 removeAllHandlers(cPtr
);
866 if (cPtr
->delegate
&& cPtr
->delegate
->didDie
)
867 (*cPtr
->delegate
->didDie
)(cPtr
->delegate
, cPtr
);
870 } else if (nbytes
==0) { /* the other side has closed connection */
871 cPtr
->state
= WCClosed
;
872 removeAllHandlers(cPtr
);
873 if (cPtr
->delegate
&& cPtr
->delegate
->didDie
)
874 (*cPtr
->delegate
->didDie
)(cPtr
->delegate
, cPtr
);
876 aData
= WMCreateDataWithBytes(buffer
, nbytes
);
884 WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
) /*FOLD00*/
886 wassertr(cPtr
->sock
>= 0);
887 /* Don't try to set the delegate multiple times */
888 wassertr(cPtr
->delegate
== NULL
);
890 cPtr
->delegate
= delegate
;
891 if (delegate
&& delegate
->didReceiveInput
&& !cPtr
->handler
.read
)
892 cPtr
->handler
.read
= WMAddInputHandler(cPtr
->sock
, WIReadMask
,
894 if (delegate
&& delegate
->didCatchException
&& !cPtr
->handler
.exception
)
895 cPtr
->handler
.exception
= WMAddInputHandler(cPtr
->sock
, WIExceptMask
,
902 WMIsConnectionNonBlocking(WMConnection
*cPtr
) /*FOLD00*/
907 state
= fcntl(cPtr
->sock
, F_GETFL
, 0);
910 /* If we can't use fcntl on socket, this probably also means we could
911 * not use fcntl to set non-blocking mode, and since a socket defaults
912 * to blocking when created, return False as the best assumption */
916 return ((state
& NONBLOCK_OPT
)!=0);
918 return cPtr
->isNonBlocking
;
925 WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
) /*FOLD00*/
927 wassertrv(cPtr
!=NULL
&& cPtr
->sock
>=0, False
);
929 if (cPtr
->isNonBlocking
== flag
)
932 if (setSocketNonBlocking(cPtr
->sock
, flag
)==True
) {
933 cPtr
->isNonBlocking
= flag
;
942 WMSetConnectionCloseOnExec(WMConnection
*cPtr
, Bool flag
)
944 wassertrv(cPtr
!=NULL
&& cPtr
->sock
>=0, False
);
946 if (fcntl(cPtr
->sock
, F_SETFD
, (flag
? FD_CLOEXEC
: 0)) < 0) {
955 WMGetConnectionClientData(WMConnection
*cPtr
) /*FOLD00*/
957 return cPtr
->clientData
;
962 WMSetConnectionClientData(WMConnection
*cPtr
, void *data
) /*FOLD00*/
964 cPtr
->clientData
= data
;
969 WMGetConnectionFlags(WMConnection
*cPtr
) /*FOLD00*/
976 WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
) /*FOLD00*/
978 cPtr
->uflags
= flags
;
983 WMGetConnectionUnsentData(WMConnection
*cPtr
)
985 return cPtr
->outputQueue
;
990 WMSetConnectionDefaultTimeout(unsigned int timeout
) /*FOLD00*/
993 DefaultTimeout
= DEF_TIMEOUT
;
995 DefaultTimeout
= timeout
;
1001 WMSetConnectionOpenTimeout(unsigned int timeout
) /*FOLD00*/
1004 OpenTimeout
= DefaultTimeout
;
1006 OpenTimeout
= timeout
;
1012 WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
) /*FOLD00*/
1015 cPtr
->sendTimeout
.timeout
= DefaultTimeout
;
1017 cPtr
->sendTimeout
.timeout
= timeout
;