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