Debian Codegraph @

COSMIC/Saccept.c

raw
1 /* Saccept.c: this file contains the Socket accept support
2 * Authors: Charles E. Campbell, Jr.
3 * Terry McRoberts
4 * Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
5 * Permission is hereby granted to use and distribute this code,
6 * with or without modifications, provided that this copyright
7 * notice is copied with it. Like anything else that's free,
8 * Saccept.c is provided *as is* and comes with no warranty
9 * of any kind, either expressed or implied. By using this
10 * software, you agree that in no event will the copyright
11 * holder be liable for any damages resulting from the use
12 * of this software.
13 * Date: Aug 22, 2005
14 */
15 #include <stdio.h>
16 #include <errno.h>
17 #include "sockets.h"
18
19 /* ------------------------------------------------------------------------- */
20
21 /* Saccept: this routine uses a server Socket to accept connections
22 * The accept() function clones a socket for use with a client connect.
23 * One may close the Saccept generated socket without affecting the
24 * server socket.
25 */
26 #ifdef __PROTOTYPE__
27 Socket *Saccept(Socket *skt)
28 #else
29 Socket *Saccept(skt)
30 Socket *skt;
31 #endif
32 {
33 #if defined(_AIX)
34 size_t addrlen;
35 #elif defined(__gnu_linux__)
36 socklen_t addrlen;
37 #else
38 int addrlen;
39 #endif
40 #ifndef SSLNOSETSOCKOPT
41 int status=1;
42 #endif
43 struct sockaddr addr;
44 Socket *acceptskt= NULL;
45
46
47 /* sanity check */
48 if(!skt) {
49 return acceptskt;
50 }
51
52 /* allocate a Socket */
53 acceptskt= makeSocket(skt->hostname,skt->sktname,PM_ACCEPT);
54 if(!acceptskt) {
55 return acceptskt;
56 }
57
58 /* accept a connection */
59 addrlen = sizeof (addr);
60 acceptskt->skt= accept(skt->skt, &addr, &addrlen);
61 if (acceptskt->skt < 0) { /* failure to accept */
62 freeSocket(acceptskt);
63 return (Socket *) NULL;
64 }
65
66 /* turn off TCP's buffering algorithm so small packets don't get delayed */
67 #ifndef SSLNOSETSOCKOPT
68
69
70 if(setsockopt(skt->skt,IPPROTO_TCP,TCP_NODELAY,(char *) &status,sizeof(status)) < 0) {
71 }
72 #endif /* #ifndef SSLNOSETSOCKOPT ... */
73
74 return acceptskt;
75 }
76
77 /* ---------------------------------------------------------------------
78 * vim: ts=4
79 */