File: saccept.c

package info (click to toggle)
robotour 3.1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,972
  • sloc: cpp: 17,705; sh: 3,060; ansic: 2,778; makefile: 144
file content (68 lines) | stat: -rwxr-xr-x 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Just put in another line */
/* Saccept.c: this file contains the Socket accept support */
#include <stdio.h>
#include <errno.h>
#include "sockets.h"

/* ------------------------------------------------------------------------- */

/* Saccept: this routine uses a server Socket to accept connections
 *  The accept() function clones a socket for use with a client connect.
 *  One may close the Saccept generated socket without affecting the
 *  server socket.
 */
#ifdef __PROTOTYPE__
Socket *Saccept(Socket *skt)
#else
Socket *Saccept(skt)
Socket *skt;
#endif
{
#ifdef _AIX
size_t          addrlen;
#else
int             addrlen;
#endif
#ifndef SSLNOSETSOCKOPT
int             status=1;
#endif
struct sockaddr addr;
Socket         *acceptskt= NULL;


/* sanity check */
if(!skt) {
	return acceptskt;
	}

/* allocate a Socket */
acceptskt= makeSocket(skt->hostname,skt->sktname,PM_ACCEPT);
if(!acceptskt) {
	return acceptskt;
	}

/* accept a connection */
addrlen       = sizeof (addr);
acceptskt->skt= accept(skt->skt, &addr, &addrlen);
if(acceptskt->skt <= 0) {	/* failure to accept */

	freeSocket(acceptskt);


	return (Socket *) NULL;
	}

/* turn off TCP's buffering algorithm so small packets don't get delayed */
#ifndef SSLNOSETSOCKOPT


if(setsockopt(skt->skt,IPPROTO_TCP,TCP_NODELAY,(char *) &status,sizeof(status)) < 0) {
	}
#endif	/* #ifndef SSLNOSETSOCKOPT ... */

return acceptskt;
}

/* ---------------------------------------------------------------------
 * vim: ts=4
 */