]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/listen.c
2 * "$Id: listen.c,v 1.1 1999/06/18 16:43:02 mike Exp $"
4 * Server listening routines for the Common UNIX Printing System (CUPS)
7 * Copyright 1997-1999 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44145 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636-3111 USA
21 * Voice: (301) 373-9603
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
27 * StartListening() - Create all listening sockets...
28 * StopListening() - Close all listening sockets...
32 * Include necessary headers...
39 * 'StartListening()' - Create all listening sockets...
45 int i
, /* Looping var */
46 val
; /* Parameter value */
47 listener_t
*lis
; /* Current listening socket */
51 * Setup socket listeners...
54 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
56 LogMessage(LOG_DEBUG
, "StartListening() address=%08x port=%d",
57 ntohl(lis
->address
.sin_addr
.s_addr
),
58 ntohs(lis
->address
.sin_port
));
60 if ((lis
->fd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1)
62 LogMessage(LOG_ERROR
, "StartListening() Unable to open listen socket - %s.",
67 fcntl(lis
->fd
, F_SETFD
, fcntl(lis
->fd
, F_GETFD
) | FD_CLOEXEC
);
70 * Set things up to reuse the local address for this port.
75 setsockopt(lis
->fd
, SOL_SOCKET
, SO_REUSEADDR
, (char *)&val
, sizeof(val
));
77 setsockopt(lis
->fd
, SOL_SOCKET
, SO_REUSEADDR
, &val
, sizeof(val
));
81 * Bind to the port we found...
84 if (bind(lis
->fd
, (struct sockaddr
*)&(lis
->address
), sizeof(lis
->address
)) < 0)
86 LogMessage(LOG_ERROR
, "StartListening() Unable to bind socket - %s.", strerror(errno
));
91 * Listen for new clients.
94 if (listen(lis
->fd
, SOMAXCONN
) < 0)
96 LogMessage(LOG_ERROR
, "StartListening() Unable to listen for clients - %s.",
102 * Setup the select() input mask to contain the listening socket we have.
105 DEBUG_printf(("StartListening: Adding fd %d to InputSet...\n", lis
->fd
));
106 FD_SET(lis
->fd
, &InputSet
);
109 LogMessage(LOG_DEBUG
, "StartListening() NumListeners=%d", NumListeners
);
114 * 'StopListening()' - Close all listening sockets...
120 int i
; /* Looping var */
121 listener_t
*lis
; /* Current listening socket */
124 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
126 #if defined(WIN32) || defined(__EMX__)
127 closesocket(lis
->fd
);
130 #endif /* WIN32 || __EMX__ */
132 DEBUG_printf(("StopListening: Removing fd %d from InputSet...\n", lis
->fd
));
133 FD_CLR(lis
->fd
, &InputSet
);
136 LogMessage(LOG_DEBUG
, "StopListening()");
141 * End of "$Id: listen.c,v 1.1 1999/06/18 16:43:02 mike Exp $".