
154
"C" Programming Guide For Optimus S/R
Example
SOCKET s;
struct sockaddr_in name;
s = socket (PF_INET, SOCK_STREAM, TCP);
if (s < 0) {
printf ("SOCKET allocation failed");
...................
}
memset (&name, 0, sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons (3000);
if (bind (s, (struct sockaddr*) &name, sizeof (name)) < 0) {
printf ("Error in Binding on socket: %d", s);
...................
}
if (listen (s, l) {
printf ("Error in Listening on socket: %d", s);
...................
}
Description
This routine is used with connection-oriented socket type SOCK_STREAM; it
is part of the sequence of routines that are called to perform a passive open.
listen() puts the bound socket in a state in which it is listening up to a
backlog
number of connection requests from clients.
The socket is put into passive open where incoming connection requests
are acknowledged and queued pending acceptance by the accept() process.
This routine is typically used by servers that can have more than one
connection request at a time. If a connection request arrives and the queue
is full, the client will receive an error.
If there are no available socket descriptors, listen() attempts to continue to
function. When descriptors become available, a later call to listen() or
accept() will refill the queue to the current or most recent
backlog
, if
possible, and resume listening for incoming connections.
If listen() is called on an already listening socket, it will return success
without changing the
backlog
. Setting the
backlog
to 0 in a subsequent call
to listen() on a listening socket is not considered a proper reset, especially
if there are connections on the socket.
Return
If successful, it returns 0.
On error, it returns -1.
The global variable
errno
is set to indicate the error condition encountered.
See Also
accept, connect
Содержание Optimus R
Страница 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Страница 6: ......
Страница 8: ...2 C Programming Guide For Optimus S R...
Страница 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Страница 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Страница 24: ...18 C Programming Guide For Optimus S R...
Страница 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...
Страница 232: ...226 C Programming Guide For Optimus S R 4 11 Implementation defined Limits limits h float h Refer to limit h and float h...
Страница 238: ...232 C Programming Guide For Optimus S R...