comparison packages/net/tcpip/current/doc/socket.html @ 97:ced4577552cd ecos-sw-2000-06-06

Merge from eCos master repository on 2000-06-06-08:44:00-BST
author jlarmour
date Tue, 06 Jun 2000 08:39:36 +0000
parents
children
comparison
equal deleted inserted replaced
96:b15c60e34c84 97:ced4577552cd
1 <html>
2 <body>
3 <pre>
4 NAME
5 socket - create an endpoint for communication
6
7 SYNOPSIS
8 #include &lt;network.h&gt;
9
10 int socket(int domain, int type, int protocol);
11
12 DESCRIPTION
13 Socket creates an endpoint for communication and returns a
14 descriptor.
15
16 The domain parameter specifies a communications domain
17 within which communication will take place; this selects
18 the protocol family which should be used. These families
19 are defined in &lt;network.h&gt;. The currently understood
20 formats include:
21
22 PF_INET
23 IPv4 Internet protocols; see ip(4)
24
25 The socket has the indicated type, which specifies the
26 semantics of communication. Currently defined types are:
27
28 SOCK_STREAM
29 Provides sequenced, reliable, two-way connection-
30 based byte streams. An out-of-band data transmis-
31 sion mechanism may be supported.
32
33 SOCK_DGRAM
34 Supports datagrams (connectionless, unreliable mes-
35 sages of a fixed maximum length).
36
37 SOCK_SEQPACKET
38 Provides a sequenced, reliable, two-way connection-
39 based data transmission path for datagrams of fixed
40 maximum length; a consumer is required to read an
41 entire packet with each read system call.
42
43 SOCK_RAW
44 Provides raw network protocol access.
45
46 The protocol specifies a particular protocol to be used
47 with the socket. Normally only a single protocol exists
48 to support a particular socket type within a given proto-
49 col family. However, it is possible that many protocols
50 may exist, in which case a particular protocol must be
51 specified in this manner. The protocol number to use is
52 particular to the "communication domain" in which communi-
53 cation is to take place; see protocols(5). See getpro-
54 toent(3) on how to map protocol name strings to protocol
55 numbers.
56
57 Sockets of type SOCK_STREAM are full-duplex byte streams,
58 similar to pipes. A stream socket must be in a connected
59 state before any data may be sent or received on it. A
60 connection to another socket is created with a connect(2)
61 call. Once connected, data may be transferred using
62 read(2) and write(2) calls or some variant of the send(2)
63 and recv(2) calls. When a session has been completed a
64 close(2) may be performed. Out-of-band data may also be
65 transmitted as described in send(2) and received as
66 described in recv(2).
67
68 The communications protocols which implement a SOCK_STREAM
69 ensure that data is not lost or duplicated. If a piece of
70 data for which the peer protocol has buffer space cannot
71 be successfully transmitted within a reasonable length of
72 time, then the connection is considered When SO_KEEPALIVE
73 is enabled on the socket the protocol checks in a proto-
74 col-specific manner if the other end is still alive.
75
76 SOCK_DGRAM and SOCK_RAW sockets allow sending of datagrams
77 to correspondents named in send(2) calls. Datagrams are
78 generally received with recvfrom(2), which returns the
79 next datagram with its return address.
80
81 When the network signals an error condition to the proto-
82 col module (e.g. using a ICMP message for IP) the pending
83 error flag is set for the socket. The next operation on
84 this socket will return the error code of the pending
85 error. For some protocols it is possible to enable a per-
86 socket error queue to retrieve detailed information about
87 the error; see IP_RECVERR in ip(4).
88
89 The operation of sockets is controlled by socket level
90 options. These options are defined in <sys/socket.h>.
91 Setsockopt(2) and getsockopt(2) are used to set and get
92 options, respectively.
93
94 RETURN VALUES
95 -1 is returned if an error occurs; otherwise the return
96 value is a descriptor referencing the socket.
97
98 ERRORS
99 EPROTONOSUPPORT
100 The protocol type or the specified protocol is not
101 supported within this domain.
102
103 EMFILE There are too many open files.
104
105 EACCES Permission to create a socket of the specified
106 type and/or protocol is denied.
107
108 ENOBUFS or ENOMEM
109 Insufficient memory is available. The socket can-
110 not be created until sufficient resources are
111 freed.
112
113 EINVAL Unknown protocol, or protocol family not avail-
114 able.
115 </pre>
116 </body>
117 </html>