📄 network.txt
字号:
Set minimum count for output. This count is the mininum number of bytes that must be stored
in the send buffer before actually sending them on the network. optval is an int.
SO_RCVLOWAT
Set minimum count for input. This count is the mininum number of bytes that must be received
in the receive buffer before returning from a call reading from the socket. optval is an int
.
SO_SNDTIMEO
Set timeout for output calls. optval is an struct timeval.
SO_RCVTIMEO
Set timeout for input calls. optval is an struct timeval.
SO_TYPE
For getsockopt only: get the type of socket. optval is an int.
SO_TYPE
For getsockopt only: get the last error on the socket. optval is an int.
RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the
following values:
ENOPROTOOPT: the option is not valid for the protocol specified.
EBADF, ENOTSOCK and EFAULT.
*************************************************************************************
listen
SYNOPSIS
int listen(int s, int backlog);
PARAMETERS
s: [in] the socket that will accept connections.
backlog: [in] the maximum number of queued connections.
DESCRIPTION
Notifies to the operating system the the task is ready to accept connections on a socket and
specifies the maximum number of incomming connections that can be queued for that socket.
RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the
following values:
EOPNOTSUPP: the socket protocol does not support the listen call.
EBADF or ENOTSOCK.
*************************************************************************************
recv, recvfrom and recvmsg
SYNOPSIS
int recv(int s, void *buf, int len, unsigned int flags);
int recvfrom(int s, void *buf, int len, unsigned int flags struct sockaddr *from,
int *fromlen);
int recvmsg(int s, struct msghdr *msg, unsigned int flags);
PARAMETERS
s: [in] the socket to read from.
buf: [out] points to a buffer where to put the information read.
len: [in] the capacity of the buffer.
flags: [in] several options (see description).
from: [out] points to an area where to store the peer address. If NULL, the peer address is
not stored.
fromlen: [in out] on entry, points to a number indicating the capacity of from. On return,
points to an area where to store the actual length of from.
msg: [out] points to an area where to store the incomming message header.
DESCRIPTION
recv is usually used to receive messages form a connection-oriented socket. It is equivalent
to recvfrom with from set to NULL.
recvfrom and recvmsg are used for connection-less or connection-oriented sockets.
These calls block if there is no message to receive unless the socket is non-blocking.
The flags parameter may have the following values:
MSG_OOB
the call will receive out-of-band data instead of in band data.
MSG_PEEK
return the data from the input queue without dequeuing it.
MSG_WAITALL
wait until all data requested is received (buf is full).
recvmsg is not yet implemented in Linux.
RETURN VALUE
On success, the number of bytes received. On error, the call returns -1 and sets errno to
one of the following values:
EBADF, ENOTCONN, ENOTSOCK, EWOULDBLOCK, EINTR or EFAULT.
*************************************************************************************
send, sendmsg and sendto
SYNOPSIS
int send(int s, const void *buf, int len, unsigned int flags);
int sendto(int s, const void *buf, int len, unsigned int flags, const struct sockaddr *to,
int tolen);
int sendmsg(int s, const struct msghdr *msg , unsigned int flags);
PARAMETERS
s: [in] the socket on which to send.
buf: [in] points to the buffer that contains the data to send.
len: [in] the lenght of buf.
flags: [in] some flags (see description).
to: [in] points to the peer address where to send the data.
tolen: [in] the length of to.
msg: [in] the message to send.
DESCRIPTION
sendmsg is not yet implemented.
send is used to send data on a connection-oriented socket. sendto and sendmsg are used on
connection-less or connection-oriented sockets. Unless the socket is non-blocking the call
will block until the data is send.
The flags may be one or more or'ed values from the following:
MSG_OOB
send the data out-of-band.
MSG_DONTROUTE
bypass the routing facilities of the system.
RETURN VALUE
On success, returns the number of bytes sent. On error, the call returns -1 and sets errno
to one of the following values:
EMSGSIZE: the data is too big to be sent atomically.
ENOBUFS: the system has not enought memory to allocate an output buffer or the output queue
for the network interface is full.
EBADF, ENOTCONN, ENOTSOCK, EWOULDBLOCK, EINTR or EFAULT.
*************************************************************************************
shutdown
SYNOPSIS
int shutdown(int s, int how);
PARAMETERS
s: [in] the socket to shutdown.
how: [in] how to do it.
DESCRIPTION
Terminates the communication on a socket. The possible values for how are:
0 the socket can no longer receive.
1 the socket can no longer send.
2 the socket can no longer receive or send.
RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the
following values:
EBADF, ENOTSOCK or ENOTCONN.
*************************************************************************************
socket
SYNOPSIS
int socket(int domain, int type, int protocol);
PARAMETERS
domain: [in] the protocol family of the socket.
type: [in] its type.
protocol: [in] the protocol used for communications.
DESCRIPTION
Creates a communication endpoint. The domain parameter can take the following values:
AF_UNIX
Unix internal protocols.
AF_INET
ARPA protocols (TCP/IP and so on).
AF_ISO
ISO protocols.
AF_NS
Xerox Network System protocols.
AF_IMPLINK
IMP link layer.
As of version 1.0 of Linux: AF_ISO, AF_IMPLINK and AF_NS are not supported.
The type parameter may take the following values:
SOCK_STREAM
full-duplex, reliable, sequenced, connection-oriented stream. Out-of-band data may be
supported.
SOCK_DGRAM
connection-less, unreliable link for datagram transmission.
SOCK_RAW
only a task with superuser privileges may use this options (see kernel).
SOCK_SEQPACKET
full-duplex, reliable, sequenced, connection-oriented link for datagram of a specified size.
Usable only with the AF_NS domain.
SOCK_RDM
not implemented yet.
The SOCK_STREAM type provide reliable transmission. Even when the connection is not
transmitting usefull information, a packet is send at a regular interval to ensure that
the connection is still intact.
RETURN VALUE
On success, a new file descriptor for the socket is returned. On error, -1 is returned and
errno is set to one of the following values:
EACCESS: the calling task does not have permission to create a socket of the specified
domain, type and protocol.
EPROTONOSUPPORT, EMFILE, ENFILE or ENOBUFFS.
*************************************************************************************
socketpair
SYNOPSIS
int socketpair(int domain, int type, int protocol, int sv[2]);
PARAMETERS
domain: [in] the socket protocol family.
type: [in] the socket type.
protocol: [in] the socket protocol.
sv: [out] the two file descriptors.
DESCRIPTION
Creates a pair of interconnected sockets. The two sockets are indistinguishable. See socket
for more information on domains, types and protocols. See section socket
Linux 1.0 supports only the AF_UNIX domain for this call.
RETURN VALUE
On success, zero is returned. On error, -1 is returned and errno is set to one of the
following values:
EACCESS: the calling task does not have permission to create a socket of the specified
domain, type and protocol.
EPROTONOSUPPORT, EAFNOSUPPORT, EOPNOSUPPORT, EMFILE, ENFILE, EFAULT or ENOBUFFS.
*************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -