2012-04-02 08:56:30 +02:00
|
|
|
#ifndef SOCKET_H
|
|
|
|
#define SOCKET_H
|
2012-03-28 13:24:49 +02:00
|
|
|
|
|
|
|
namespace icinga {
|
|
|
|
|
2012-04-06 08:56:52 +02:00
|
|
|
struct I2_BASE_API SocketErrorEventArgs : public EventArgs
|
2012-04-04 12:22:46 +02:00
|
|
|
{
|
|
|
|
typedef shared_ptr<SocketErrorEventArgs> Ptr;
|
|
|
|
typedef weak_ptr<SocketErrorEventArgs> WeakPtr;
|
|
|
|
|
|
|
|
int Code;
|
|
|
|
string Message;
|
|
|
|
};
|
|
|
|
|
2012-04-06 08:56:52 +02:00
|
|
|
class I2_BASE_API Socket : public Object
|
2012-03-28 13:24:49 +02:00
|
|
|
{
|
2012-03-29 13:15:54 +02:00
|
|
|
private:
|
2012-03-28 13:24:49 +02:00
|
|
|
SOCKET m_FD;
|
|
|
|
|
2012-04-18 15:22:25 +02:00
|
|
|
int ExceptionEventHandler(const EventArgs& ea);
|
2012-04-04 12:22:46 +02:00
|
|
|
|
2012-04-04 16:02:19 +02:00
|
|
|
protected:
|
2012-04-04 12:22:46 +02:00
|
|
|
string FormatErrorCode(int errorCode);
|
|
|
|
|
2012-03-29 13:15:54 +02:00
|
|
|
protected:
|
2012-03-28 13:24:49 +02:00
|
|
|
Socket(void);
|
|
|
|
|
|
|
|
void Close(bool from_dtor);
|
|
|
|
|
|
|
|
public:
|
2012-04-02 20:50:35 +02:00
|
|
|
typedef shared_ptr<Socket> Ptr;
|
|
|
|
typedef weak_ptr<Socket> WeakPtr;
|
2012-03-28 13:24:49 +02:00
|
|
|
|
2012-04-02 20:50:35 +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);
|
|
|
|
|
2012-04-18 15:22:25 +02:00
|
|
|
Event<EventArgs> OnReadable;
|
|
|
|
Event<EventArgs> OnWritable;
|
|
|
|
Event<EventArgs> OnException;
|
2012-03-28 13:24:49 +02:00
|
|
|
|
2012-04-18 15:22:25 +02:00
|
|
|
Event<SocketErrorEventArgs> OnError;
|
|
|
|
Event<EventArgs> 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:56:30 +02:00
|
|
|
#endif /* SOCKET_H */
|