Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 8
Create an endpoint for communication
#include <sys/types.h>
#include <sys/socket.h>
int socket( int domain,
int type,
int protocol );
- domain
- The communications domain that you want to use.
This selects the protocol family that should be used.
These families are defined in <sys/socket.h>.
- type
- The type of socket you want to create.
This determines the semantics of communication.
Here are the currently defined types:
- SOCK_STREAM — provides sequenced, reliable,
two-way, connection-based byte streams. An out-of-band data
transmission mechanism may be supported.
- SOCK_DGRAM — supports datagrams, which are
connectionless, unreliable messages of a fixed (typically small) maximum
length.
- SOCK_RAW — provides access to internal network
protocols and interfaces.
Available only to the superuser, this type isn't described here.
For more information, see below.
- protocol
- The particular protocol that you want to use with the socket.
Normally, only a single protocol exists to support a particular socket
type within a given protocol family.
But if many protocols exist, you must specify one.
The protocol number you give is particular to the communication
domain where communication is to take place (see
/etc/protocols
in the Utilities Reference).
libsocket
Use the -l socket option to
qcc
to link against this library.
The socket() function creates an endpoint for
communication and returns a descriptor.
SOCK_STREAM sockets are full-duplex byte streams, similar to
pipes. A stream socket must be in a connected state
before any data may be sent or received on it.
To create a connection to another socket, call
connect()
call.
Once the socket is connected, you can transfer data by using
read() and
write()
or some variant of
send() and
recv().
When a session has been completed, a
close()
may be performed. Out-of-band data may
also be transmitted (as described in send()) and
received (as described in recv()).
The communications protocols used to implement a SOCK_STREAM
socket ensure that data isn't lost or duplicated. If a piece
of data that the peer protocol has buffer space for can't be
successfully transmitted within a reasonable length of time,
the connection is considered broken and calls will indicate
an error by returning -1 and setting errno to
ETIMEDOUT.
With SOCK_DGRAM and SOCK_RAW sockets, datagrams can be sent
to correspondents named in
send() calls.
Datagrams are generally received with
recvfrom(),
which returns the next datagram with its return address.
You can use the
ioctl()
call to specify a process group to receive a SIGURG signal when the out-of-band data
arrives. The call may also enable nonblocking I/O and
asynchronous notification of I/O events via SIGIO.
The operation of sockets is controlled by socket-level options.
These options are defined in the file <sys/socket.h>.
Use
setsockopt() and
getsockopt()
to set and get options.
A descriptor referencing the socket, or -1 if an error occurs
(errno is set).
- EACCES
- Permission to create a socket of the specified type
and/or protocol is denied.
- EAFNOSUPPORT
- The specified address family isn't supported.
- EMFILE
- The per-process descriptor table is full.
- ENFILE
- The system file table is full.
- ENOBUFS
- Insufficient buffer space available. The socket can't
be created until sufficient resources are freed.
- ENOMEM
- Not enough memory.
- EPROTONOSUPPORT
- The protocol type or the specified protocol isn't
supported within this domain.
POSIX 1003.1
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
By default, socket() communicates with the TCP/IP stack managing
the /dev/socket portion of the namespace.
You can change this behavior by setting the SOCK
environment variable.
For an example, see
“Running multiple instances of the TCP/IP stack”
in the TCP/IP Networking chapter of the
Neutrino User's Guide.
ICMP6,
ICMP,
INET6,
IPv6,
IP,
IPsec,
ROUTE,
TCP,
UDP,
UNIX
protocols
accept(),
bind(),
close(),
connect(),
getprotobyname(),
getsockname(),
getsockopt(),
ioctl(),
listen(),
read(),
recv(),
select(),
send(),
shutdown(),
socketpair(),
write()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 318
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/socket.html on line 318