23 #include "common_priv.h"
38 : context(ctx), logger(ctx.get(),
Logger::INFO), enabled(true)
44 std::deque<FileHandle*> files;
54 unsigned num = sock.Read(&packet.header,
sizeof(packet.header));
55 if (num !=
sizeof(packet.header)) {
58 if (!packet.Valid()) {
64 Key_t key = packet.DestinationKey();
65 shared_ptr<PendingConnection> conn;
66 std::pair<PendingMap::iterator, PendingMap::iterator> range;
68 PendingMap::iterator entry = range.first;
69 PendingMap::iterator end = range.second;
70 while (entry != end) {
71 if (!entry->second->Done()) {
98 itr->second->Cancel();
104 return shared_ptr<Sync::Future<int> >();
107 shared_ptr<PendingConnection> conn;
113 std::string hostname;
114 std::string servname;
115 context->GetKernelConnectionInfo(kernelkey, hostname, servname);
119 packet.
SourceKey(writerkey).DestinationKey(readerkey);
121 if (num !=
sizeof(packet.
header)) {
124 conn->Set(sock.
FD());
136 return shared_ptr<Sync::Future<int> >();
139 shared_ptr<PendingConnection> conn;
145 conn = entry->second;
166 entry->second->Cancel();
183 std::pair<PendingMap::iterator, PendingMap::iterator> range;
185 PendingMap::iterator entry = range.first;
186 PendingMap::iterator end = range.second;
187 while (entry != end) {
188 if (entry->second.get() == conn) {
197 : key(k), server(serv)
212 server->PendingDone(key,
this);
Logger object that is used for forwarding log messages.
void Listen(const SocketAddress &addr, int queuelength=256)
int Accept(SocketAddress &addr)
An abstraction of a socket address with convenience methods.
A FileHandle customized with some socket specific functionality and functions.
ServerSocketHandle server
PendingConnection(Key_t k, ConnectionServer *serv)
The Context abstract data type.
void Error(const char *fmt,...)
uint64_t SourceKey() const
shared_ptr< Context > context
void PendingDone(Key_t key, PendingConnection *conn)
void Read()
Read until not readable anymore.
static int Poll(IteratorRef< FileHandle * > begin, IteratorRef< FileHandle * > end, double timeout)
poll a list of FileHandles for any activity and call the appropriate On method.
AutoLock< PthreadMutex > AutoPLock
void SetFromSockName(int fd)
Fill this SocketAddress with data from this side of the connection represented by fd...
void Close()
Close the file and reset the internal state.
shared_ptr< Sync::Future< int > > ConnectReader(Key_t readerkey)
ConnectionServer(SockAddrList addrs, shared_ptr< Context > ctx)
SocketAddress GetAddress()
void Reset()
Clear all internal state including the file descriptor! WARNING does not close the file! ...
static SockAddrList CreateIP(unsigned serv)
Return a list of valid socket address for the given service number or port number.
bool Readable(bool r)
Set that the file is currently readable or not.
std::vector< SocketAddress > SockAddrList
virtual const char * what() const
void Connect(const SocketAddress &addr)
Create a new socket and try to connect to the given address.
PendingMap pendingconnections
shared_ptr< Sync::Future< int > > ConnectWriter(Key_t writerkey)
Automatic locking on the stack.
unsigned Write(const void *ptr, unsigned len)
Write data to the file descriptor.