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
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/inetserversocket.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2002 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_INETSERVERSOCKET_H</font>
<font color="#a020f0">#define RUDIMENTS_INETSERVERSOCKET_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/inetserversocketincludes.h></font>
<font color="#0000ff">// The inetserversocket class allows you to write programs that can talk to</font>
<font color="#0000ff">// other programs across a network over TCP stream sockets.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// The inetserversocket class provides methods for setting up sockets and</font>
<font color="#0000ff">// accepting client connections. Its ultimate parent class: transport,</font>
<font color="#0000ff">// provides methods for reading and writing data and closing connections.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// If you need to listen on more than 1 socket at a time, you should use the </font>
<font color="#0000ff">// inetserversocket class (and possibly the unixserversocket class) in</font>
<font color="#0000ff">// conjunction with the listener class.</font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#2e8b57"><b>class</b></font> inetserversocketprivate;
<font color="#2e8b57"><b>class</b></font> inetserversocket : <font color="#a52a2a"><b>public</b></font> serversocket, <font color="#a52a2a"><b>private</b></font> inetsocketutil {
<font color="#a52a2a"><b>public</b></font>:
inetserversocket();
inetserversocket(<font color="#2e8b57"><b>const</b></font> inetserversocket &i);
inetserversocket &<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> inetserversocket &i);
<font color="#2e8b57"><b>virtual</b></font> ~inetserversocket();
<font color="#2e8b57"><b>bool</b></font> listen(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *address,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> port,
<font color="#2e8b57"><b>int</b></font> backlog);
<font color="#0000ff">// Listen on "address" and "port" and allow</font>
<font color="#0000ff">// "backlog" connections to pile up before</font>
<font color="#0000ff">// refusing them.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// To listen on all addresses enter a NULL</font>
<font color="#0000ff">// for "address". Entering a value of 0 for</font>
<font color="#0000ff">// the "port" causes the server to listen on an</font>
<font color="#0000ff">// arbitrary port.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// The getPort() method can be used later to </font>
<font color="#0000ff">// discover this port.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">// If you need to set socket options or do anything special</font>
<font color="#0000ff">// between the discrete steps of socket initialization, you</font>
<font color="#0000ff">// should use a combination of these methods.</font>
<font color="#2e8b57"><b>bool</b></font> initialize(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *address, <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> port);
<font color="#0000ff">// Creates the actual socket and Initializes the class</font>
<font color="#0000ff">// to use "address" and "port" when bind() is called.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#2e8b57"><b>bool</b></font> bind();
<font color="#0000ff">// Associates the socket with an address.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#2e8b57"><b>bool</b></font> listen(<font color="#2e8b57"><b>int</b></font> backlog);
<font color="#0000ff">// Waits until a client connects then places</font>
<font color="#0000ff">// that connection in queue. Up to "backlog"</font>
<font color="#0000ff">// connections may be queued before future</font>
<font color="#0000ff">// conenctions are refused.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
filedescriptor *accept();
<font color="#0000ff">// Removes the client connection from the queue</font>
<font color="#0000ff">// and associates a new socket with that</font>
<font color="#0000ff">// connection. Communication with the client</font>
<font color="#0000ff">// may be done over this new socket. </font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns an inetsocket on success and NULL</font>
<font color="#0000ff">// on failure.</font>
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> getPort();
<font color="#0000ff">// Returns the inet port number that</font>
<font color="#0000ff">// the socket is listening on. If the</font>
<font color="#0000ff">// port has not been set, 0 is </font>
<font color="#0000ff">// returned instead.</font>
<font color="#0000ff">// Writes the address of the client at</font>
<font color="#0000ff">// the other end of "sock" to "buffer".</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/inetserversocket.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|