|
|
1.1 root 1: .\" Copyright (c) 1983 Regents of the University of California.
2: .\" All rights reserved. The Berkeley software License Agreement
3: .\" specifies the terms and conditions for redistribution.
4: .\"
5: .\" @(#)send.2 6.4 (Berkeley) 7/21/87
6: .\"
7: .TH SEND 2 "July 21, 1987"
8: .UC 5
9: .SH NAME
10: send, sendto, sendmsg \- send a message from a socket
11: .SH SYNOPSIS
12: .nf
13: .ft B
14: #include <sys/types.h>
15: #include <sys/socket.h>
16: .PP
17: .ft B
18: cc = send(s, msg, len, flags)
19: int cc, s;
20: char *msg;
21: int len, flags;
22: .PP
23: .ft B
24: cc = sendto(s, msg, len, flags, to, tolen)
25: int cc, s;
26: char *msg;
27: int len, flags;
28: struct sockaddr *to;
29: int tolen;
30: .PP
31: .ft B
32: cc = sendmsg(s, msg, flags)
33: int cc, s;
34: struct msghdr *msg;
35: int flags;
36: .fi
37: .SH DESCRIPTION
38: .IR Send ,
39: .IR sendto ,
40: and
41: .I sendmsg
42: are used to transmit a message to another socket.
43: .I Send
44: may be used only when the socket is in a
45: .I connected
46: state, while
47: .I sendto
48: and
49: .I sendmsg
50: may be used at any time.
51: .PP
52: The address of the target is given by
53: .I to
54: with
55: .I tolen
56: specifying its size.
57: The length of the message is given by
58: .IR len .
59: If the message is too long to pass atomically through the
60: underlying protocol, then the error EMSGSIZE is returned, and
61: the message is not transmitted.
62: .PP
63: No indication of failure to deliver is implicit in a
64: .IR send .
65: Return values of \-1 indicate some locally detected errors.
66: .PP
67: If no messages space is available at the socket to hold
68: the message to be transmitted, then
69: .I send
70: normally blocks, unless the socket has been placed in
71: non-blocking I/O mode.
72: The
73: .IR select (2)
74: call may be used to determine when it is possible to
75: send more data.
76: .PP
77: The
78: .I flags
79: parameter may include one or more of the following:
80: .PP
81: .nf
82: .RS
83: .ta \w'#define\ \ 'u +\w'MSG_DONTROUTE\ \ \ 'u +\w'0x\0\0\0\ \ 'u
84: #define MSG_OOB 0x1 /* process out-of-band data */
85: #define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */
86: .RE
87: .fi
88: The flag MSG_OOB is used to send \*(lqout-of-band\*(rq
89: data on sockets that support this notion (e.g. SOCK_STREAM);
90: the underlying protocol must also support \*(lqout-of-band\*(rq data.
91: MSG_DONTROUTE is usually used only by diagnostic or routing programs.
92: .PP
93: See
94: .IR recv (2)
95: for a description of the
96: .I msghdr
97: structure.
98: .SH "RETURN VALUE
99: The call returns the number of characters sent, or \-1
100: if an error occurred.
101: .SH "ERRORS
102: .TP 20
103: [EBADF]
104: An invalid descriptor was specified.
105: .TP 20
106: [ENOTSOCK]
107: The argument \fIs\fP is not a socket.
108: .TP 20
109: [EFAULT]
110: An invalid user space address was specified for a parameter.
111: .TP 20
112: [EMSGSIZE]
113: The socket requires that message be sent atomically,
114: and the size of the message to be sent made this impossible.
115: .TP 20
116: [EWOULDBLOCK]
117: The socket is marked non-blocking and the requested operation
118: would block.
119: .TP 20
120: [ENOBUFS]
121: The system was unable to allocate an internal buffer.
122: The operation may succeed when buffers become available.
123: .TP 20
124: [ENOBUFS]
125: The output queue for a network interface was full.
126: This generally indicates that the interface has stopped sending,
127: but may be caused by transient congestion.
128: .SH SEE ALSO
129: fcntl(2), recv(2), select(2), getsockopt(2), socket(2), write(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.