00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __W32SOCK_H__
00012 #define __W32SOCK_H__
00013
00014 #include "sockio.h"
00015
00016 class win_socket : public socket_t {
00017 protected:
00018 SOCKET s;
00019 int errcode;
00020 char* address;
00021
00022 enum error_codes {
00023 ok = 0,
00024 not_opened = -1,
00025 bad_address = -2,
00026 connection_failed = -3,
00027 broken_pipe = -4,
00028 invalid_access_mode = -5
00029 };
00030
00031 public:
00032 bool open(int listen_queue_size);
00033 bool connect(int max_attempts, time_t timeout);
00034
00035 int read(void* buf, size_t min_size, size_t max_size,time_t timeout);
00036 bool write(void const* buf, size_t size);
00037
00038 bool is_ok();
00039 bool close();
00040 char* get_peer_name();
00041 bool shutdown();
00042 void get_error_text(char* buf, size_t buf_size);
00043
00044 socket_t* accept();
00045 bool cancel_accept();
00046
00047 int get_handle();
00048
00049 win_socket(const char* address);
00050 win_socket(SOCKET new_sock);
00051
00052 ~win_socket();
00053 };
00054
00055 #define SOCKET_BUF_SIZE (8*1024)
00056 #define ACCEPT_TIMEOUT (30*1000)
00057
00058 class local_win_socket : public socket_t {
00059 protected:
00060 enum error_codes {
00061 ok = 0,
00062 not_opened = -1,
00063 broken_pipe = -2,
00064 timeout_expired = -3
00065 };
00066 enum socket_signals {
00067 RD,
00068 RTR,
00069 TD,
00070 RTT
00071 };
00072
00073
00074
00075
00076
00077
00078 struct socket_buf {
00079 volatile int RcvWaitFlag;
00080 volatile int SndWaitFlag;
00081 volatile int DataEnd;
00082 volatile int DataBeg;
00083 char Data[SOCKET_BUF_SIZE - 4*sizeof(int)];
00084 };
00085 struct accept_data {
00086 HANDLE Signal[4];
00087 HANDLE BufHnd;
00088 };
00089 struct connect_data {
00090 HANDLE Mutex;
00091 int Pid;
00092 };
00093 socket_buf* RcvBuf;
00094 socket_buf* SndBuf;
00095 HANDLE Signal[4];
00096 HANDLE Mutex;
00097 HANDLE BufHnd;
00098 int Error;
00099 char* Name;
00100
00101 public:
00102 bool open(int listen_queue_size);
00103 bool connect(int max_attempts, time_t timeout);
00104
00105 int read(void* buf, size_t min_size, size_t max_size,time_t timeout);
00106 bool write(void const* buf, size_t size);
00107
00108 char* get_peer_name();
00109 bool is_ok();
00110 bool close();
00111 bool shutdown();
00112 void get_error_text(char* buf, size_t buf_size);
00113
00114 socket_t* accept();
00115 bool cancel_accept();
00116
00117 int get_handle();
00118
00119 local_win_socket(const char* address);
00120 local_win_socket();
00121
00122 ~local_win_socket();
00123 };
00124
00125 #endif
00126
00127
00128
00129
00130