]>
Commit | Line | Data |
---|---|---|
904ec517 | 1 | /* ------------------------------------------------------------------------- |
99d80019 JS |
2 | * Project: GSocket (Generic Socket) for WX |
3 | * Name: gsockmsw.h | |
4 | * Copyright: (c) Guilhem Lavaux | |
5 | * Licence: wxWindows Licence | |
6 | * Purpose: GSocket MSW header | |
7 | * CVSID: $Id$ | |
904ec517 GRG |
8 | * ------------------------------------------------------------------------- |
9 | */ | |
10 | ||
2804f77d VZ |
11 | #ifndef _WX_MSW_GSOCKMSW_H_ |
12 | #define _WX_MSW_GSOCKMSW_H_ | |
904ec517 | 13 | |
4b4d23c7 | 14 | #include "wx/msw/wrapwin.h" |
c21b68f7 | 15 | |
9e07d399 RN |
16 | #if defined(__CYGWIN__) |
17 | //CYGWIN gives annoying warning about runtime stuff if we don't do this | |
18 | # define USE_SYS_TYPES_FD_SET | |
19 | # include <sys/types.h> | |
20 | #endif | |
21 | ||
22 | #if defined(__WXWINCE__) || defined(__CYGWIN__) | |
dbfb61b3 JS |
23 | #include <winsock.h> |
24 | #endif | |
25 | ||
904ec517 | 26 | /* Definition of GSocket */ |
4b4d23c7 | 27 | class GSocket |
904ec517 | 28 | { |
4b4d23c7 DE |
29 | public: |
30 | GSocket(); | |
31 | ~GSocket(); | |
32 | bool IsOk() { return m_ok; } | |
33 | void Close(); | |
34 | void Shutdown(); | |
35 | GSocketError SetLocal(GAddress *address); | |
36 | GSocketError SetPeer(GAddress *address); | |
37 | GAddress *GetLocal(); | |
38 | GAddress *GetPeer(); | |
39 | GSocketError SetServer(); | |
40 | GSocket *WaitConnection(); | |
2804f77d VZ |
41 | // not used under MSW |
42 | void Notify(bool) { } | |
948c96ef | 43 | bool SetReusable(); |
60edcf45 VZ |
44 | bool SetBroadcast(); |
45 | bool DontDoBind(); | |
4b4d23c7 DE |
46 | GSocketError Connect(GSocketStream stream); |
47 | GSocketError SetNonOriented(); | |
48 | int Read(char *buffer, int size); | |
49 | int Write(const char *buffer, int size); | |
50 | GSocketEventFlags Select(GSocketEventFlags flags); | |
51 | void SetNonBlocking(bool non_block); | |
52 | void SetTimeout(unsigned long millis); | |
a4506848 | 53 | GSocketError WXDLLIMPEXP_NET GetError(); |
4b4d23c7 DE |
54 | void SetCallback(GSocketEventFlags flags, |
55 | GSocketCallback callback, char *cdata); | |
56 | void UnsetCallback(GSocketEventFlags flags); | |
57 | GSocketError GetSockOpt(int level, int optname, | |
58 | void *optval, int *optlen); | |
59 | GSocketError SetSockOpt(int level, int optname, | |
60 | const void *optval, int optlen); | |
8c029a5b VZ |
61 | |
62 | void SetInitialSocketBuffers(int recv, int send) | |
63 | { | |
64 | m_initialRecvBufferSize = recv; | |
65 | m_initialSendBufferSize = send; | |
66 | } | |
67 | ||
4b4d23c7 DE |
68 | protected: |
69 | GSocketError Input_Timeout(); | |
70 | GSocketError Output_Timeout(); | |
71 | GSocketError Connect_Timeout(); | |
72 | int Recv_Stream(char *buffer, int size); | |
73 | int Recv_Dgram(char *buffer, int size); | |
74 | int Send_Stream(const char *buffer, int size); | |
75 | int Send_Dgram(const char *buffer, int size); | |
76 | bool m_ok; | |
8c029a5b VZ |
77 | int m_initialRecvBufferSize; |
78 | int m_initialSendBufferSize; | |
4b4d23c7 DE |
79 | |
80 | /* TODO: Make these protected */ | |
81 | public: | |
904ec517 GRG |
82 | SOCKET m_fd; |
83 | GAddress *m_local; | |
84 | GAddress *m_peer; | |
85 | GSocketError m_error; | |
86 | ||
483249fc | 87 | /* Attributes */ |
948c96ef DE |
88 | bool m_non_blocking; |
89 | bool m_server; | |
90 | bool m_stream; | |
91 | bool m_establishing; | |
92 | bool m_reusable; | |
60edcf45 VZ |
93 | bool m_broadcast; |
94 | bool m_dobind; | |
904ec517 GRG |
95 | struct timeval m_timeout; |
96 | ||
97 | /* Callbacks */ | |
483249fc | 98 | GSocketEventFlags m_detected; |
904ec517 GRG |
99 | GSocketCallback m_cbacks[GSOCK_MAX_EVENT]; |
100 | char *m_data[GSOCK_MAX_EVENT]; | |
101 | int m_msgnumber; | |
102 | }; | |
103 | ||
104 | /* Definition of GAddress */ | |
105 | struct _GAddress | |
106 | { | |
107 | struct sockaddr *m_addr; | |
108 | size_t m_len; | |
109 | ||
110 | GAddressType m_family; | |
111 | int m_realfamily; | |
112 | ||
113 | GSocketError m_error; | |
114 | }; | |
115 | ||
904ec517 GRG |
116 | |
117 | /* GAddress */ | |
118 | ||
119 | GSocketError _GAddress_translate_from(GAddress *address, | |
120 | struct sockaddr *addr, int len); | |
d3ea6527 GRG |
121 | GSocketError _GAddress_translate_to (GAddress *address, |
122 | struct sockaddr **addr, int *len); | |
904ec517 GRG |
123 | GSocketError _GAddress_Init_INET(GAddress *address); |
124 | GSocketError _GAddress_Init_UNIX(GAddress *address); | |
125 | ||
2804f77d | 126 | #endif /* _WX_MSW_GSOCKMSW_H_ */ |