CPN
Computational Process Networks
ServerSocketHandle.h
Go to the documentation of this file.
1 //=============================================================================
2 // Computational Process Networks class library
3 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you
16 // can write to the Free Software Foundation, Inc., 59 Temple Place -
17 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18 // World Wide Web at http://www.fsf.org.
19 //=============================================================================
23 #ifndef SERVERSOCKETHANDLE_H
24 #define SERVERSOCKETHANDLE_H
25 #pragma once
26 #include <cpn/common.h>
27 #include <cpn/io/FileHandle.h>
28 #include <cpn/io/SocketAddress.h>
29 
34 public:
35 
37  ServerSocketHandle(int nfd) : FileHandle(nfd), reuse_addr(false) {}
38  ServerSocketHandle(const SocketAddress &addr, int queuelength = 256) : reuse_addr(false)
39  { Listen(addr, queuelength); }
40  ServerSocketHandle(const SockAddrList &addrs, int queuelength = 256) : reuse_addr(false)
41  { Listen(addrs, queuelength); }
42 
47  void Listen(const SocketAddress &addr, int queuelength = 256);
48 
53  void Listen(const SockAddrList &addrs, int queuelength = 256);
54 
61  int Accept(SocketAddress &addr);
65  int Accept();
66 
70  void SetReuseAddr(bool reuse = true) { reuse_addr = true; }
71  bool GetReuseAddr() { return reuse_addr; }
72 private:
73  bool Listen(const SocketAddress &addr, int queuelength, int &error);
74  int Accept(SocketAddress *addr);
75  bool reuse_addr;
76 };
77 #endif
void Listen(const SocketAddress &addr, int queuelength=256)
ServerSocketHandle(const SockAddrList &addrs, int queuelength=256)
An abstraction of a socket address with convenience methods.
Definition: SocketAddress.h:42
A class to make it easy to deal with file descriptors.
void SetReuseAddr(bool reuse=true)
Turn on reuse of the address. Only takes effect if set before Listen.
std::vector< SocketAddress > SockAddrList
Definition: SocketAddress.h:35
ServerSocketHandle(const SocketAddress &addr, int queuelength=256)
Generic file handle could be a file, or a socket or a device.
Definition: FileHandle.h:41