Main Page | Class Hierarchy | Class List | File List | Class Members

w32sock.h

00001 //-< W32SOCK.H >-----------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:      8-May-97    K.A. Knizhnik  * / [] \ *
00006 //                          Last update:  8-May-97    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Windows sockets
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __W32SOCK_H__
00012 #define __W32SOCK_H__
00013 
00014 #include "sockio.h"
00015 
00016 BEGIN_GIGABASE_NAMESPACE
00017 
00018 class win_socket : public socket_t {
00019   protected:
00020     SOCKET        s;
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_t* buf, size_t buf_size);
00043 
00044     socket_t* accept();
00045     bool      cancel_accept();
00046 
00047     win_socket(const char* address);
00048     win_socket(SOCKET new_sock);
00049 
00050     ~win_socket();
00051 };
00052 
00053 #define SOCKET_BUF_SIZE (8*1024)
00054 #define ACCEPT_TIMEOUT  (30*1000)
00055 
00056 class local_win_socket : public socket_t {
00057   protected:
00058     enum error_codes {
00059         ok = 0,
00060         not_opened = -1,
00061         broken_pipe = -2,
00062         timeout_expired = -3
00063     };
00064     enum socket_signals {
00065         RD,  // receive data
00066         RTR, // ready to receive
00067         TD,  // transfer data
00068         RTT  // ready to transfer
00069     };
00070     //------------------------------------------------------
00071     // Mapping between signals at opposite ends of socket:
00072     // TD  ---> RD
00073     // RTR ---> RTT
00074     //------------------------------------------------------
00075 
00076     struct socket_buf {
00077         volatile int RcvWaitFlag;
00078         volatile int SndWaitFlag;
00079         volatile int DataEnd;
00080         volatile int DataBeg;
00081         char Data[SOCKET_BUF_SIZE - 4*sizeof(int)];
00082     };
00083     struct accept_data {
00084         HANDLE Signal[4];
00085         HANDLE BufHnd;
00086     };
00087     struct connect_data {
00088         HANDLE Mutex;
00089         int    Pid;
00090     };
00091     socket_buf* RcvBuf;
00092     socket_buf* SndBuf;
00093     HANDLE      Signal[4];
00094     HANDLE      Mutex;
00095     HANDLE      BufHnd;
00096     int         Error;
00097     char*     Name;
00098 
00099   public:
00100     bool      open(int listen_queue_size);
00101     bool      connect(int max_attempts, time_t timeout);
00102 
00103     int       read(void* buf, size_t min_size, size_t max_size,time_t timeout);
00104     bool      write(void const* buf, size_t size);
00105 
00106     char*   get_peer_name();
00107     bool      is_ok();
00108     bool      close();
00109     bool      shutdown();
00110     void      get_error_text(char_t* buf, size_t buf_size);
00111 
00112     socket_t* accept();
00113     bool      cancel_accept();
00114 
00115     local_win_socket(const char* address);
00116     local_win_socket();
00117 
00118     ~local_win_socket();
00119 };
00120 
00121 END_GIGABASE_NAMESPACE
00122 
00123 #endif

Generated on Thu Feb 12 18:46:27 2004 for GigaBASE by doxygen 1.3.5