File: Socket.html

package info (click to toggle)
libape 1.0.0-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,572 kB
  • ctags: 1,343
  • sloc: sh: 7,342; cpp: 3,418; makefile: 117
file content (240 lines) | stat: -rw-r--r-- 9,044 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<HTML><HEAD><TITLE>Socket Class</TITLE></HEAD>
<BODY bgcolor="#ffffff">

<H1>Socket Class Reference</H1>
<p>
[<A HREF="index.html">APE Index</A>] [<A HREF="hier.html">APE Hierarchy</A>]
[<A HREF="header-list.html">Headers</A>]
</p>
<HR>
<P> The Socket is used as the base for all Internet protocol services
 under APE   <a href="#short">More...</a></P>
<P>
<code>
	#include &lt;<a href="socket-h.html">socket.h</a>&gt;
</code>

</P>

<H2>Public Members</H2>
<UL>
<LI>virtual <b><a name="ref0">~Socket</a></b> () 
</LI>
<LI> <b><a href="#ref1">Socket</a></b> (int domain, int type, int protocol = 0) 
</LI>
<LI> <b><a href="#ref2">Socket</a></b> (int fd) 
</LI>
<LI> <b><a href="#ref3">Socket</a></b> (const Socket &amp;source) 
</LI>
<LI>Socket&amp; <b><a href="#ref4">operator=</a></b> (const Socket &amp;from) 
</LI>
<LI>void <b><a href="#ref5">setCompletion</a></b> (int mode) 
</LI>
<LI>inline virtual int <b><a href="#ref6">Read</a></b> (void *addr, size_t len) 
</LI>
<LI>inline virtual int <b><a href="#ref7">Write</a></b> (void *addr, size_t len) 
</LI>
<LI>inline virtual int <b><a href="#ref8">Write</a></b> (char *msg) 
</LI>
<LI>inline virtual int <b><a href="#ref9">Peek</a></b> (void *addr, size_t len) 
</LI>
<LI>InetHostAddress <b><a href="#ref10">Peek</a></b> (short *port = NULL) 
</LI>
<LI>friend inline InetHostAddress <b><a name="ref11">peek</a></b> (Socket &amp;s, short *port = NULL) 
</LI>
<LI>friend inline int <b><a name="ref12">read</a></b> (Socket &amp;s, void *addr, size_t len) 
</LI>
<LI>friend inline int <b><a name="ref13">write</a></b> (Socket &amp;s, void *addr, size_t len) 
</LI>
<LI>friend inline int <b><a name="ref14">write</a></b> (Socket &amp;s, char *msg) 
</LI>
<LI>friend inline int <b><a name="ref15">peek</a></b> (Socket &amp;s, void *addr, size_t len) 
</LI>
</UL>

<H2>Protected Members</H2>
<UL>
<LI>	int <b><a name="ref16">state</a></b>
</LI>
<LI>	int <b><a name="ref17">so</a></b>
</LI>
</UL>
<HR>
<H2><a name="short">Detailed Description</a></H2>
<P>

 The Socket is used as the base for all Internet protocol services
 under APE.  A socket is a system resource (or winsock descriptor)
 that occupies a specific port address (and may be bound to a specific
 network interface) on the local machine.  The socket may also be
 directly connected to a specific socket on a remote internet host.

</P><HR>
<H3><b> <a name="ref1"></a><a name="Socket">Socket</a>(int domain, int type, int protocol = 0)  </b><code>[public]</code></H3>
<p>An unconnected socket may be created directly on the local
machine.  Sockets can occupy both the internet domain (AF_INET)
and UNIX socket domain (AF_UNIX) under unix.  The socket type
(SOCK_STREAM, SOCK_DGRAM) and protocol may also be specified.
If the socket cannot be created, an exception is thrown.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
domain</td><td align="left" valign="top">
socket domain to use.</td></tr>
<tr><td align="left" valign="top">
protocol</td><td align="left" valign="top">
specific protocol to apply.</td></tr>
<tr><td align="left" valign="top">
type</td><td align="left" valign="top">
base type and protocol family of the socket.</td></tr>
</table>
</dl>
<H3><b> <a name="ref2"></a><a name="Socket">Socket</a>(int fd)  </b><code>[public]</code></H3>
<p>A socket object may be created from a file descriptor when that
descriptor was created either through a socket() or accept()
call.  This constructor is mostly for internal use.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
fd</td><td align="left" valign="top">
file descriptor of an already existing socket.</td></tr>
</table>
</dl>
<H3><b> <a name="ref3"></a><a name="Socket">Socket</a>(const <a href="Socket.html">Socket</a> &amp;source)  </b><code>[public]</code></H3>
<p>A socket can also be constructed from an already existing
Socket object.  The socket file descriptor is dup()'d.  This
does not exist under win32.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
source</td><td align="left" valign="top">
of existing socket to clone.</td></tr>
</table>
</dl>
<H3><b><a href="Socket.html">Socket</a>&amp; <a name="ref4"></a><a name="operator=">operator=</a>(const <a href="Socket.html">Socket</a> &amp;from)  </b><code>[public]</code></H3>
<p>Sockets may also be duplicated by the assignment operator.
</p>
<H3><b>void <a name="ref5"></a><a name="setCompletion">setCompletion</a>(int mode)  </b><code>[public]</code></H3>
<p>Used to specify blocking mode for the socket.  A socket
can be made non-blocking by setting SOCKET_COMPLETION_DELAYED
or set to block on all access with SOCKET_COMPLETION_IMMEDIATE.
I do not believe this form of non-blocking socket I/O is supported
in winsock, though it provides an alternate asynchronous set of
socket services.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
mode</td><td align="left" valign="top">
specify socket I/O call blocking mode.</td></tr>
</table>
</dl>
<H3><b>inlineint <a name="ref6"></a><a name="Read">Read</a>(void *addr, size_t len)  </b><code>[public virtual]</code></H3>
<p>Read an arbitrary byte data stream from the socket.  This
is made a virtual function so that derived classes can
implement special data encoding for specific protocols such
as in-stream MIME decoding, or to create timed streaming
services.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
addr</td><td align="left" valign="top">
pointer to store read data.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to read.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes read on success, -1 on error.</dl>
<H3><b>inlineint <a name="ref7"></a><a name="Write">Write</a>(void *addr, size_t len)  </b><code>[public virtual]</code></H3>
<p>Write an arbitrary byte data stream from the socket.  This
is made a virtual function so that derived classes can
implement special data encoding for specific protocols such
as in-stream MIME encoding, or to create timed streaming
services.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
addr</td><td align="left" valign="top">
pointer to write data from.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to write.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes written on success, -1 on error.</dl>
<H3><b>inlineint <a name="ref8"></a><a name="Write">Write</a>(char *msg)  </b><code>[public virtual]</code></H3>
<p>Write a null terminated string directly to a socket.  This
is made a virtual function so that derived classes can
implement special data encoding for specific protocols such
as in-stream MIME encoding, or to create timed streaming
services.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
msg</td><td align="left" valign="top">
null terminated ASCII string to write.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes written on success, -1 on failure.</dl>
<H3><b>inlineint <a name="ref9"></a><a name="Peek">Peek</a>(void *addr, size_t len)  </b><code>[public virtual]</code></H3>
<p>This allows one to peek at data waiting at the "head stream"
of the socket.  Peeking allows protocols to determine both if
data is available, and, for some protocols, what kind of data
to expect, to make processing more efficient.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
addr</td><td align="left" valign="top">
to read socket head queue into.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to try and read from the socket.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes available.</dl>
<H3><b><a href="InetHostAddress.html">InetHostAddress</a> <a name="ref10"></a><a name="Peek">Peek</a>(short *port = NULL)  </b><code>[public]</code></H3>
<p>This specific Peek method can be used to return the internet 
host address of the sender of the next packet to be read.  For
TCP servers, the Peek method can be used to determine the
address of the next socket connection request and thereby
determine if it should be accepted or not.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
pointer to store port address of sending socket.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
address of sending host.</dl>
<HR>
<TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top">
<address>Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
<address>
</TD><TD ALIGN="RIGHT" VALIGN="TOP">
<b>K</b><i>doc</i>
</TD>
</TR></TABLE></BODY></HTML>