File: unixserversocket.h.html

package info (click to toggle)
rudiments 0.32-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,932 kB
  • ctags: 3,047
  • sloc: cpp: 23,013; sh: 7,769; ansic: 1,769; makefile: 1,057; xml: 169; perl: 19
file content (105 lines) | stat: -rw-r--r-- 7,060 bytes parent folder | download | duplicates (2)
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
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/unixserversocket.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_UNIXSERVERSOCKET_H</font>
<font color="#a020f0">#define RUDIMENTS_UNIXSERVERSOCKET_H</font>

<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/unixserversocketincludes.h&gt;</font>

<font color="#0000ff">// The unixserversocket class allows you to write programs that can talk to</font>
<font color="#0000ff">// other programs on the same machine over TCP stream sockets.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Inet sockets (see the inetserversocket class) can be used by clients and</font>
<font color="#0000ff">// servers on the same machine as well, but Unix sockets generally perform</font>
<font color="#0000ff">// better.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// The unixserversocket 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">// An immediate parent class: unixsocket provides methods for passing file</font>
<font color="#0000ff">// descriptors between connected instances of unixservertsocket's and</font>
<font color="#0000ff">// unixclientsocket's.</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">// unixserversocket 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> unixserversocketprivate;

<font color="#2e8b57"><b>class</b></font> unixserversocket : <font color="#a52a2a"><b>public</b></font> serversocket, <font color="#a52a2a"><b>private</b></font> unixsocketutil {
        <font color="#a52a2a"><b>public</b></font>:
                                unixserversocket();
                                unixserversocket(<font color="#2e8b57"><b>const</b></font> unixserversocket &amp;u);
                unixserversocket        &amp;<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> unixserversocket &amp;u);
                <font color="#2e8b57"><b>virtual</b></font>               ~unixserversocket();

                <font color="#2e8b57"><b>bool</b></font>  listen(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *filename,
                                        mode_t mask,
                                        <font color="#2e8b57"><b>int</b></font> backlog);
                                <font color="#0000ff">// Listen on &quot;filename&quot; and allow &quot;backlog&quot;</font>
                                <font color="#0000ff">// connections to pile up before refusing them.</font>
                                <font color="#0000ff">// Set the permissions on &quot;filename&quot; using</font>
                                <font color="#0000ff">// umask &quot;mask&quot;.</font>
                                <font color="#0000ff">//</font>
                                <font color="#0000ff">// Returns true on success and false on failure.</font>



                <font color="#0000ff">// The following 9 methods provide discrete control over socket</font>
                <font color="#0000ff">// initialization.</font>
                <font color="#0000ff">//</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> *filename, mode_t mask);
                        <font color="#0000ff">// Creates the actual socket and initializes the class</font>
                        <font color="#0000ff">// to use &quot;filename&quot; when bind() is called.  The</font>
                        <font color="#0000ff">// permissions on &quot;filename&quot; will be set using umask</font>
                        <font color="#0000ff">// &quot;mask&quot;.</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 &quot;backlog&quot;</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="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/unixserversocket.h&gt;</font>
};

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>

<font color="#a020f0">#endif</font>
</pre>
</body>
</html>