00001
00002
00003
00004 #ifndef __NETSOCKET_H__
00005 #define __NETSOCKET_H__
00006
00007 #include <string>
00008 #include <sys/select.h>
00009 #include <boost/signal.hpp>
00010
00011 #define NETSOCKET_TEMPBUF_SIZE 1024
00012 #define NETSOCKET_OUTPUT_BUF_SIZE 1024
00013
00014 namespace ircpp {
00015
00016 class netsocket
00017 {
00018 public:
00019
00020 netsocket();
00021 ~netsocket();
00022
00023
00024 bool connect(const std::string &host, int port);
00025 bool disconnect();
00026 bool connected();
00027
00028
00029 bool service_socket(fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int *maxfd);
00030 bool send(const std::string &data);
00031
00032
00033 boost::signal1<void, const std::string&> sig_data;
00034 boost::signal0<void> sig_connected;
00035 boost::signal1<void, const std::string&> sig_disconnected;
00036 boost::signal2<void, const std::string&, int> sig_error;
00037
00038
00039 int get_errno();
00040
00041 private:
00042
00043 bool _send();
00044
00045
00046 private:
00047 int fd;
00048 bool is_connected;
00049 char tempbuf[NETSOCKET_TEMPBUF_SIZE];
00050 int tempbuf_len;
00051 int errorno;
00052 std::string output_buffer;
00053 };
00054
00055 }
00056
00057 #endif