OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
wsksock.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Winsock for OWL subsystem.
7/// Based on work by Paul Pedriana, 70541.3223@compuserve.com
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_WSKSOCK_H)
11#define OWL_WSKSOCK_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18#include <owl/window.h>
19#include <owl/wskaddr.h>
20
21
22namespace owl {
23
24#define WINSOCK_NOERROR (int)0
25#define WINSOCK_ERROR (int)SOCKET_ERROR
26
27#define N_DEF_MAX_READ_BUFFFER_SIZE 8192
28
29//
30//
31//
32#define MSG_SOCKET_NOTIFY ((UINT)(WM_USER+301)) ///< User-defined message used for socked notifications
33#define FD_ALL (FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT|FD_CONNECT|FD_CLOSE)
34#define FD_NONE (0)
35
36//
37/// Enumeration describing the type of event notifications you want to
38/// receive for a given socket.
39//
41 NotifyNone = 0x00, ///< No notifications
42 NotifyRead = 0x01, ///< Notification of readiness for reading
43 NotifyWrite = 0x02, ///< Notification of readiness for writing
44 NotifyOOB = 0x04, ///< Notification of the arrival of out-of-band data
45 NotifyAccept = 0x08, ///< Notification of incoming connections
46 NotifyConnect = 0x10, ///< Notification of completed connection
47 NotifyClose = 0x20, ///< Notification of socket closure
48 NotifyAll = 0x3F ///< All notifications
49};
50
51//
52// Forward ref.
53//
54class _OWLCLASS TSocket;
55
56#include <owl/preclass.h>
57
58//
59/// \class TSocketWindow
60// ~~~~~ ~~~~~~~~~~~~~
61/// Derived from TWindow, a private window used to catch notification messages.
62//
64 public:
67
68 void SetNotificationSet(int notificationSet);
69 void SetNotificationWindow(TWindow* windowNotification);
70
71 int GetLastError();
72 int StartAcceptNotification();
73 int StartRegularNotification();
74 int StartCustomNotification(int selectOptions);
75 int CancelNotification();
76
77 TSocket* GetSocketParent() const;
78 void SetSocketParent(TSocket* socket);
79
81 static uint MsgSocketNotification; ///< Message used to notify hwndNotification, if hwndNotification is used.
82 TSocket* SocketParent; ///< Exported so Parent can have easy access to it.
83
84 protected:
85 int SelectOptions; ///< We need to keep our own copy of this so we can do an assignment operator.
86 TWindow* WindowNotification; ///< A second window that can be notified instead of the Socket.
87 int NotificationSet; ///< Types of notification to respond to
88 int LastError; ///< Last error
89
90 TResult DoNotification(TParam1, TParam2);
91
93};
94
95//
96/// \class TSocket
97// ~~~~~ ~~~~~~~
98/// TSocket encapsulates the basic attributes of a socket. A socket is an endpoint
99/// of communication to which a name may be bound. Each socket in use has a type and
100/// an associated process.
101//
103 public:
104 /// How to shutdown the socket.
105 //
107 ShutModeNoRecv = 0, ///< No more receives on the socket.
108 ShutModeNoSend = 1, ///< No more sends on the socket.
109 ShutModeNoRecvSend = 2 ///< No more sends or receives.
110 };
111
112 TSocket();
115 int nNewType = SOCK_STREAM, int nNewProtocol = 0);
116 virtual ~TSocket();
117
118 operator SOCKET() const;
119 virtual int CloseSocket();
120 virtual int ShutDownSocket(TShutMode shutMode = ShutModeNoRecvSend);
121
123 friend bool operator ==(const TSocket& socket1, const TSocket& socket2);
124
125 // Commands
126 //
127 virtual void SetNotificationSet(int notificationSet);
128 virtual void SetNotificationWindow(TWindow* windowNotification);
129 virtual int CreateSocket();
130 /// binds to a given address
131 //
132 virtual int BindSocket(const TSocketAddress& addressToBindTo);
133
134 /// binds to our address
135 //
136 virtual int BindSocket();
137 virtual void SetMyAddress(TSocketAddress& newSocketAddress);
138 virtual void SetPeerSocketAddress(TSocketAddress& newPeerSocketAddress);
139 virtual void SetSocketStyle(int nNewFamily = PF_INET,
140 int nNewType = SOCK_STREAM,
141 int nNewProtocol = 0);
142 virtual int StartAcceptNotification();
143 virtual int StartRegularNotification();
144 virtual int StartCustomNotification(int nSelectionOptions);
145 virtual int CancelNotification();
146
147 // Tells class Sockete not to close the socket on deletion.
148 bool SetSaveSocketOnDelete(bool saveSocket = true);
149
150 virtual int ConvertProtocol(char* protocol);
151
152 // Info
153 //
154 int GetLastError();
155 virtual ulong GetDriverWaitingSize();
156 virtual ulong GetTotalWaitingSize();
157 virtual int GetMyAddress( TSocketAddress& socketAddress,
158 int& nAddressLength, SOCKET& socket);
159 virtual int GetMyAddress( TSocketAddress& socketAddress,
160 int& nAddressLength);
161 virtual int GetPeerAddress( TSocketAddress& socketAddress,
162 int& nAddressLength, SOCKET& socket);
163 virtual int GetPeerAddress( TSocketAddress& socketAddress,
164 int& nAddressLength);
165
166 // Read/Write (Send/Receive)
167 //
168 virtual void SetMaxReadBufferSize(int nNewMaxReadBufferSize);
169
170 // Options
171 //
172 int SetBroadcastOption(bool bBroadcast);
173 int SetDebugOption(bool bDebug);
174 int SetLingerOption(bool bLinger, ushort nLingerTime=0);
175 int SetRouteOption(bool bRoute);
176 int SetKeepAliveOption(bool bKeepAlive);
177 int SetOOBOption(bool bSendOOBDataInline);
178 int SetReceiveBufferOption(int nReceiveBufferSize);
179 int SetSendBufferOption(int nSendBufferSize);
180 int SetReuseAddressOption(bool bAllowReuseAddress);
181
182 int GetBroadcastOption(bool& bBroadcast);
183 int GetDebugOption(bool& bDebug);
184 int GetLingerOption(bool& bLinger, ushort& nLingerTime);
185 int GetRouteOption(bool& bRoute);
186 int GetKeepAliveOption(bool& bKeepAlive);
187 int GetOOBOption(bool& bSendOOBDataInline);
188 int GetReceiveBufferOption(int& nReceiveBufferSize);
189 int GetSendBufferOption(int& nSendBufferSize);
190 int GetReuseAddressOption(bool& bAllowReuseAddress);
191
193 SOCKET Handle; ///< The Socket handle
194 bool Bound; ///< A flag that we can use to tell if
195 ///< socket is bound or not. It gets set
196 ///< on automatically, but doesn't get
197 ///< set off automatically.
198 TSocketAddress SocketAddress; ///< My address.
199 TSocketAddress PeerSocketAddress; ///< Address of Peer to communicate with.
200 ///< Used for datagrams and connections.
201
202 protected:
203 int Family; ///< PF_INET, etc. (this is the protocol family)
204 int Type; ///< SOCK_STREAM, etc.
205 int Protocol; ///< IPPROTO_TCP, etc.
206 int LastError; ///< Last Error.
207 int MaxReadBufferSize; ///< Maximum buffer size
208 short SaveSocket; ///< Save the socket on deletion?
209 TSocketWindow Window; ///< Will receive internal notifications and pass them to this class.
210 friend class TSocketWindow;
211
212 // Protected initialization
213 //
214 void Init(); // Sets up the friend window.
215
216 int SocketsCallCheck(int error);
217
218 // Notification
219 //
220 virtual int DoReadNotification(const SOCKET& s, int nError);
221 virtual int DoWriteNotification(const SOCKET& s, int nError);
222 virtual int DoOOBNotification(const SOCKET& s, int nError);
223 virtual int DoAcceptNotification(const SOCKET& s, int nError);
224 virtual int DoConnectNotification(const SOCKET& s, int nError);
225 virtual int DoCloseNotification(const SOCKET& s, int nError);
226};
227
228#include <owl/posclass.h>
229
230
231//----------------------------------------------------------------------------
232// Inline implementations
233//
234
235//
236/// Return the last error on the socket.
237//
238inline int
243
244//
245/// Return the set of notifications socket will catch.
246//
247inline void
252
253//
254/// Set the new notification window.
255//
256inline void
261
263{
264 return SocketParent;
265}
266
268{
269 SocketParent = socket;
270}
271
272
273//
274/// Assigns new set of notifications socket will catch.
275//
276inline void
281
282//
283/// Sets the new notification window.
284//
285inline void
290
291//
292/// Returns the handle of the socket.
293//
294inline
295TSocket::operator SOCKET() const
296{
297 return Handle;
298}
299
300//
301/// Saves the socket on deletion.
302//
303inline bool
308
309//
310/// Returns the last error of the socket.
311//
312inline int
314{
315 return LastError;
316}
317
318} // OWL namespace
319
320
321#endif // OWL_WSKSOCK_H
The TSocketAddress class stores a Winsock socket address.
Definition wskaddr.h:38
TSocket encapsulates the basic attributes of a socket.
Definition wsksock.h:102
int LastError
Last Error.
Definition wsksock.h:206
virtual void SetNotificationSet(int notificationSet)
Assigns new set of notifications socket will catch.
Definition wsksock.h:277
int GetLastError()
Returns the last error of the socket.
Definition wsksock.h:313
bool SetSaveSocketOnDelete(bool saveSocket=true)
Saves the socket on deletion.
Definition wsksock.h:304
int Protocol
IPPROTO_TCP, etc.
Definition wsksock.h:205
short SaveSocket
Save the socket on deletion?
Definition wsksock.h:208
TSocketWindow Window
Will receive internal notifications and pass them to this class.
Definition wsksock.h:209
int Type
SOCK_STREAM, etc.
Definition wsksock.h:204
int Family
PF_INET, etc. (this is the protocol family)
Definition wsksock.h:203
TShutMode
How to shutdown the socket.
Definition wsksock.h:106
int MaxReadBufferSize
Maximum buffer size.
Definition wsksock.h:207
virtual void SetNotificationWindow(TWindow *windowNotification)
Sets the new notification window.
Definition wsksock.h:286
Derived from TWindow, a private window used to catch notification messages.
Definition wsksock.h:63
void SetNotificationSet(int notificationSet)
Return the set of notifications socket will catch.
Definition wsksock.h:248
TWindow * WindowNotification
A second window that can be notified instead of the Socket.
Definition wsksock.h:86
int GetLastError()
Return the last error on the socket.
Definition wsksock.h:239
TSocket * GetSocketParent() const
Definition wsksock.h:262
int LastError
Last error.
Definition wsksock.h:88
DECLARE_RESPONSE_TABLE(TSocketWindow)
void SetSocketParent(TSocket *socket)
Definition wsksock.h:267
int NotificationSet
Types of notification to respond to.
Definition wsksock.h:87
int SelectOptions
We need to keep our own copy of this so we can do an assignment operator.
Definition wsksock.h:85
void SetNotificationWindow(TWindow *windowNotification)
Set the new notification window.
Definition wsksock.h:257
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned short ushort
Definition number.h:24
unsigned long ulong
Definition number.h:26
TNotificationSet
Enumeration describing the type of event notifications you want to receive for a given socket.
Definition wsksock.h:40
@ NotifyRead
Notification of readiness for reading.
Definition wsksock.h:42
@ NotifyAccept
Notification of incoming connections.
Definition wsksock.h:45
@ NotifyOOB
Notification of the arrival of out-of-band data.
Definition wsksock.h:44
@ NotifyWrite
Notification of readiness for writing.
Definition wsksock.h:43
@ NotifyClose
Notification of socket closure.
Definition wsksock.h:47
@ NotifyAll
All notifications.
Definition wsksock.h:48
@ NotifyNone
No notifications.
Definition wsksock.h:41
@ NotifyConnect
Notification of completed connection.
Definition wsksock.h:46
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
unsigned int uint
Definition number.h:25
#define public_data
Definition defs.h:207
#define _OWLCLASS
Definition defs.h:338
Base window class TWindow definition, including HWND encapsulation.
Winsock for OWL subsystem.