CPN
Computational Process Networks
ConnectionServer.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 CPN_CONNECTIONSERVER_H
24 #define CPN_CONNECTIONSERVER_H
25 #pragma once
26 #include "common_priv.h"
28 #include <cpn/io/SocketHandle.h>
29 #include <cpn/io/WakeupHandle.h>
30 #include <cpn/utils/Logger.h>
31 #include <cpn/threading/Future.h>
33 #include <map>
34 namespace CPN {
42  public:
47  ConnectionServer(SockAddrList addrs, shared_ptr<Context> ctx);
51  void Poll();
56  void Wakeup() { wakeup.SendWakeup(); }
60  void Close();
68  shared_ptr<Sync::Future<int> > ConnectWriter(Key_t writerkey);
75  shared_ptr<Sync::Future<int> > ConnectReader(Key_t readerkey);
79  SocketAddress GetAddress();
80 
87  void Disable();
88  void Enable();
89  void LogState();
91  private:
92  class PendingConnection : public Sync::Future<int>, public SocketHandle {
93  public:
96  int Get();
97  void Set(int filed);
98  Key_t GetKey() const { return key; }
99  private:
100  const Key_t key;
102  };
103 
104  void PendingDone(Key_t key, PendingConnection *conn);
105 
106  typedef std::multimap<Key_t, shared_ptr<PendingConnection> > PendingMap;
108  shared_ptr<Context> context;
113  bool enabled;
114  };
115 }
116 #endif
Logger object that is used for forwarding log messages.
Definition: Logger.h:57
A convenience handle for event loops so that one can interrupt a Poll before it times out...
Definition: WakeupHandle.h:35
std::multimap< Key_t, shared_ptr< PendingConnection > > PendingMap
An abstraction of a socket address with convenience methods.
Definition: SocketAddress.h:42
A FileHandle customized with some socket specific functionality and functions.
Definition: SocketHandle.h:34
ServerSocketHandle server
shared_ptr< Context > context
uint64_t Key_t
Definition: common.h:79
#define CPN_LOCAL
Definition: common.h:37
A very simple logging interface.
std::vector< SocketAddress > SockAddrList
Definition: SocketAddress.h:35