aboutsummaryrefslogtreecommitdiff
path: root/lib/network/socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/network/socket.h')
-rw-r--r--lib/network/socket.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/network/socket.h b/lib/network/socket.h
new file mode 100644
index 00000000..edf9b904
--- /dev/null
+++ b/lib/network/socket.h
@@ -0,0 +1,63 @@
+#ifndef __socket_h
+#define __socket_h
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <fcntl.h>
+
+#include <lib/base/ebase.h>
+#include <lib/base/eerror.h>
+#include <lib/base/estring.h>
+#include <libsig_comp.h>
+#include <lib/base/buffer.h>
+
+class eSocket: public Object
+{
+ int mystate;
+ int issocket;
+ unsigned int last_break;
+private:
+ int socketdesc;
+ eIOBuffer readbuffer;
+ eIOBuffer writebuffer;
+ int writebusy;
+ sockaddr_in serv_addr;
+protected:
+ eSocketNotifier *rsn;
+ virtual void notifier(int);
+public:
+ eSocket(eMainloop *ml);
+ eSocket(int socket, int issocket, eMainloop *ml);
+ ~eSocket();
+ int connectToHost(eString hostname, int port);
+ int getDescriptor();
+ int writeBlock(const char *data, unsigned int len);
+ int setSocket(int socketfd, int issocket, eMainloop *ml);
+ int bytesToWrite();
+ int readBlock(char *data, unsigned int maxlen);
+ int bytesAvailable();
+ bool canReadLine();
+ eString readLine();
+ void close();
+ // flow control: start/stop data delivery into read buffer.
+ void enableRead();
+ void disableRead();
+
+ void inject(const char *data, int len);
+
+ enum State { Idle, HostLookup, Connecting,
+ Listening, Connection, Closing };
+ int state();
+
+ Signal0<void> connectionClosed_;
+ Signal0<void> connected_;
+ Signal0<void> readyRead_;
+ Signal0<void> hangup;
+ Signal1<void,int> bytesWritten_;
+ Signal1<void,int> error_;
+};
+
+#endif /* __socket_h */