icinga2/base/socket.h

62 lines
1.0 KiB
C
Raw Normal View History

#ifndef SOCKET_H
#define SOCKET_H
2012-03-28 13:24:49 +02:00
namespace icinga {
struct I2_BASE_API SocketErrorEventArgs : public EventArgs
{
typedef shared_ptr<SocketErrorEventArgs> Ptr;
typedef weak_ptr<SocketErrorEventArgs> WeakPtr;
int Code;
string Message;
};
class I2_BASE_API Socket : public Object
2012-03-28 13:24:49 +02:00
{
private:
2012-03-28 13:24:49 +02:00
SOCKET m_FD;
int ExceptionEventHandler(EventArgs::Ptr ea);
2012-04-04 16:02:19 +02:00
protected:
string FormatErrorCode(int errorCode);
protected:
2012-03-28 13:24:49 +02:00
Socket(void);
void Close(bool from_dtor);
public:
typedef shared_ptr<Socket> Ptr;
typedef weak_ptr<Socket> WeakPtr;
2012-03-28 13:24:49 +02:00
static list<Socket::WeakPtr> Sockets;
2012-03-28 13:24:49 +02:00
~Socket(void);
void SetFD(SOCKET fd);
SOCKET GetFD(void) const;
static void CloseAllSockets(void);
Event<EventArgs::Ptr> OnReadable;
Event<EventArgs::Ptr> OnWritable;
Event<EventArgs::Ptr> OnException;
2012-03-28 13:24:49 +02:00
Event<SocketErrorEventArgs::Ptr> OnError;
Event<EventArgs::Ptr> OnClosed;
2012-03-28 13:24:49 +02:00
virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const;
virtual void Start(void);
virtual void Stop(void);
void Close(void);
};
}
#endif /* SOCKET_H */