00001 00004 #include <sys/types.h> 00005 #include <sys/socket.h> 00006 #include <netdb.h> 00007 #include <arpa/inet.h> 00008 #include "low_level_net.h" 00009 00010 #define CON_NUM 10 00011 #define MAX_IPV4_SIZE 15 00012 //#define BUFF_SIZE 100000 00013 00014 #define WRITE_SIZE 4096 00015 class Hazy_Worker; 00016 00021 class Hazy_Server { 00022 private: 00024 int sockfd; 00026 buffer_handle bh; 00027 struct addrinfo hints, *servinfo; 00028 struct sockaddr_in their_addr; 00029 socklen_t sin_size; 00030 char ip[MAX_IPV4_SIZE]; // max would be lets say 111.111.111.111 = 3×4 ( nums ) + 3×1 ( dots ) = 15 00031 int rc; 00032 public: 00036 Hazy_Server(); 00040 void inetConn(); 00044 Hazy_Worker* acceptConnection(); 00048 void closeConnection(); 00049 }; 00050 00051 class Hazy_Worker { 00053 buffer_handle bh; 00055 int fd; // this the connection 00057 int buf_size; 00058 00059 public: 00064 Hazy_Worker(int fd) { 00065 bh = initialize_buffer(); 00066 this->fd = fd; 00067 } 00071 ~Hazy_Worker() { destroy_handle(bh); } 00072 00076 void* readData(); 00083 int writeData(const void *data, int size, bool intData); 00087 void closeClientConnection(); 00088 };