Brief description of class still missing. More...
#include <UnixServerStream.h>
Public Member Functions | |
virtual void | event (short type) |
virtual short | eventTypes () |
bool | listen (const char *name, int maxConnections) |
void | send (const char *bytes, int byteCount) |
UnixServerStream () | |
Protected Member Functions | |
virtual void | childDeleted (Stream *client) |
virtual UnixClientStream * | createClientStream (int fileDescriptor, const char *peer)=0 |
Brief description of class still missing.
Full description of class still missing
Description of constructor still missing
References GpCoreTools::CoreApplication::exit(), GpCoreTools::Stream::fileDescriptor(), GpCoreTools::Stream::setFileDescriptor(), TRACE, and GpCoreTools::Log::write().
: Stream() { TRACE; setFileDescriptor(socket(AF_UNIX, SOCK_STREAM, 0)); if(fileDescriptor()<=0) { Log::write(1, "server socket %s\n", strerror(errno)); CoreApplication::exit(2); } int optval=1; if(setsockopt(fileDescriptor(),SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval)) < 0) { Log::write(0, "peer tracker reuseaddr: [%i] %s\n", errno, strerror(errno)); CoreApplication::exit(2); } }
void GpCoreTools::UnixServerStream::childDeleted | ( | Stream * | client | ) | [protected, virtual] |
Reimplemented from GpCoreTools::Stream.
References TRACE.
{ TRACE; std::list<UnixClientStream *>::iterator it; for(it=_clients.begin();it!=_clients.end();it++) { if(*it==client) { break; } } if(it!=_clients.end()) { _clients.erase(it); } }
virtual UnixClientStream* GpCoreTools::UnixServerStream::createClientStream | ( | int | fileDescriptor, |
const char * | peer | ||
) | [protected, pure virtual] |
Referenced by event().
void GpCoreTools::UnixServerStream::event | ( | short | type | ) | [virtual] |
Implements GpCoreTools::Stream.
References GpCoreTools::EventLoop::addStream(), createClientStream(), GpCoreTools::Stream::fileDescriptor(), GpCoreTools::EventLoop::instance(), GpCoreTools::Stream::setParent(), TRACE, and GpCoreTools::Log::write().
{ TRACE; if(type & POLLIN) { sockaddr_un peerAddr; socklen_t peerAddrLen=sizeof(sockaddr_un); int peerFd=accept(fileDescriptor(), (sockaddr *)&peerAddr, &peerAddrLen); if(peerFd>0) { if(peerAddrLen==sizeof(sa_family_t)) { // unamed socket Log::write(2, "connection from unamed peer\n"); } else { Log::write(2, "connection from %s\n", peerAddr.sun_path); } UnixClientStream * s=createClientStream(peerFd, peerAddr.sun_path); EventLoop::instance()->addStream(s); s->setParent(this); _clients.push_back(s); } else { Log::write(1, "%s\n", strerror(errno)); } } }
virtual short GpCoreTools::UnixServerStream::eventTypes | ( | ) | [inline, virtual] |
Implements GpCoreTools::Stream.
{return POLLIN;}
bool GpCoreTools::UnixServerStream::listen | ( | const char * | name, |
int | maxConnections | ||
) |
References GpCoreTools::Stream::fileDescriptor(), GpCoreTools::UnixClientStream::setAddress(), TRACE, and GpCoreTools::Log::write().
{ TRACE; if(fileDescriptor()<=0) return false; sockaddr_un addr; UnixClientStream::setAddress(addr, name); if(bind(fileDescriptor(), (sockaddr *)&addr, sizeof(sockaddr_un))<0) { Log::write(1, "%s\n", strerror(errno)); return false; } if(::listen(fileDescriptor(), maxConnections)<0) { Log::write(1, "%s\n", strerror(errno)); return false; } else { return true; } }
void GpCoreTools::UnixServerStream::send | ( | const char * | bytes, |
int | byteCount | ||
) |