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.cpp
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#include <owl/pch.h>
10#include <owl/defs.h>
11#include <owl/winsock.h>
12
13namespace owl {
14
16
17//
18/// Default constructor for a socket. The individual members of the TSocket can be
19/// set later.
20//
22:
23 Handle(INVALID_SOCKET),
24 Bound(false),
25 Family(PF_UNSPEC),
26 Type(0),
27 Protocol(0),
28 LastError(0),
29 MaxReadBufferSize(N_DEF_MAX_READ_BUFFFER_SIZE),
30 SaveSocket(0),
31 Window(this)
32{
33 Init();
34}
35
36//
37/// TSocket(SOCKET&) is a constructor based on a Winsock SOCKET descriptor.
38//
40:
41 Handle(newS),
42 Bound(false),
43 LastError(0),
44 MaxReadBufferSize(N_DEF_MAX_READ_BUFFFER_SIZE),
45 SaveSocket(0),
46 Window(this)
47{
48 int temp;
49 GetMyAddress(SocketAddress, temp, Handle); // Fills in our address information.
50 Family = SocketAddress.sa_family;
51 GetPeerAddress(SocketAddress, temp, Handle); // Fills in out Peer's address info if it exists.
52 Init();
53}
54
55//
56/// This is the standard constructor for a TSocket. It doesn't call socket() or
57/// bind(). These must be done independently.
58//
60:
61 Handle(INVALID_SOCKET),
62 Bound(false),
63 SocketAddress(newSocketAddress),
64 Family(newFamily),
65 Type(newType),
66 Protocol(newProtocol),
67 LastError(0),
68 MaxReadBufferSize(N_DEF_MAX_READ_BUFFFER_SIZE),
69 SaveSocket(0),
70 Window(this)
71{
72 Init();
73}
74
75//
76/// This TSocket destructor will close the socket it if has not be closed already.
77/// It will also delete the friend notification window.
78//
80{
81 if (Handle != static_cast<SOCKET>(INVALID_SOCKET) && !SaveSocket) {
82 SetLingerOption(0, 60); //Don't wait till data gets sent. Just kill the socket now.
84 }
85}
86
87//
88/// This function is an intitialization function called by the TSocket constructors.
89/// It simply creates the friend window that the TSocket needs for Winsock
90/// notifications.
91//
93{
94 // This is for initialization steps that are common to all constructors.
95 //
96 try {
97 Window.Create();
98 }
99 catch (...) {
100 //::MessageBox();
101 }
102}
103
104//
105/// Checks the return error value from a sockets call, caching the last error if one
106/// occured (i.e., error is non-zero). Returns a Winsock error/noerror code.
107//
109{
110 if (error) {
112 return WINSOCK_ERROR;
113 }
114 return WINSOCK_NOERROR;
115}
116
117//
118// Does a deep copy of the TSocket, as much as possible.
119//
121{
122 Family = newSocket.Family;
123 Type = newSocket.Type;
124 Protocol = newSocket.Protocol;
125 LastError = newSocket.LastError;
126 Handle = newSocket.Handle;
127 SocketAddress = newSocket.SocketAddress;
128 PeerSocketAddress = newSocket.PeerSocketAddress;
129 SaveSocket = newSocket.SaveSocket;
130
131 // Copy the friend (helper) window. Note that there is an operator= defined
132 // for the class TSocketWindow. However, the TSocketWindow::operator= will
133 // set its 'SocketParent' member to be the newSocket SocketWindow's previous
134 // TSocket parent, which may not be us. Thus, after setting 'Window =
135 // newSocket.Window;', we set 'Window.SocketParent = this;'.
136 //
137 Window = newSocket.Window;
139
140 return *this;
141}
142
143//
144/// While it's possible that two sockets could refer to the same SOCKET (though this
145/// would likely create a mess if not governed with care), it's defined as not
146/// possible that two Sockets could have the same window member. This is because the
147/// window is created uniquely on construction for each TSocket.
148//
150{
151 return socket1.Handle == socket2.Handle && socket1.Window == socket2.Window;
152}
153
154//
155/// This function says to listen only to FD_ACCEPT messages. Note that a socket set
156/// up to be a listening socket will never be a connected socket, and a connected
157/// socket will never receive FD_ACCEPT messages. Thus all stream sockets are
158/// implicitly either connected sockets or listening sockets. Since the accepted
159/// socket needs a different notification window from the listening socket, and the
160/// sockets specification says that an accepted socket inherits the notification
161/// properties of the listening socket, the listening socket must not be set to
162/// receive FD_READ, etc, notifications. This is because it's possible that between
163/// the accept() call for the new socket and the WSAAsyncSelect() call for the new
164/// socket, data may be received for the new socket. Thus the listening socket may
165/// get sent the message and it would never get routed to the new socket. Calling
166/// this function is saying that this SocketWindow is for listening for connections.
167///
168/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
169/// GetLastError().
170//
172{
174 if (error == WINSOCK_ERROR) {
176 }
177 return error;
178}
179
180//
181/// This function turns on all Winsock notifications except FD_ACCEPT. Calling this
182/// function is saying that this SocketWindow is for connections rather than for
183/// listening. Since a Winsock socket cannot be a listening socket and a connected
184/// socket at the same time, the notification functions are separated from each
185/// other: StartAcceptNotification() and StartRegularNotification().
186///
187/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
188/// GetLastError().
189//
198
199//
200/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
201/// GetLastError().
202//
211
212//
213/// CancelNotification() turns off the notification to this window. This also
214/// changes the socket to be blocking.
215/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
216/// GetLastError().
217//
219{
221 if (error == WINSOCK_ERROR) {
223 }
224 return error;
225}
226
227//
228/// The SetSocketStyle function can be used to set or change some TSocket member
229/// data. Note that the newFamily is also represented in the TSocketAddress member,
230/// and so they should match.
231//
238
239//
240/// Converts a string protocol to integer value. Makes assumptions about the
241/// protocol string. Only "tcp" and udp return valid values.
242//
244{
245 if (!protocol)
246 return IPPROTO_TCP;
247 if (strcmp("tcp", protocol) == 0)
248 return IPPROTO_TCP;
249 if(strcmp("udp", protocol) == 0)
250 return IPPROTO_UDP;
251 return IPPROTO_IP;
252}
253
254//
255/// The CreateSocket function is much like the Winsock socket() function. This
256/// function assumes that nFamily, nType, and nProtocol are already set properly.
257/// Note also that since the return of socket() is assigned to 's', that 's' must
258/// not already be used. This is another way of saying that there can only be one
259/// SOCKET for each TSocket object.
260//
262{
264 return SocketsCallCheck(Handle == static_cast<SOCKET>(INVALID_SOCKET));
265}
266
267//
268/// The CloseSocket() function is much like the Winsock closesocket() function.
269//
271{
272 if (Handle != static_cast<SOCKET>(INVALID_SOCKET)) {
273 int error = TWinSockDll::closesocket(Handle);
274 if (error) {
276 return WINSOCK_ERROR;
277 }
278 }
279 Handle = INVALID_SOCKET; // It's invalid now.
280 Bound = false;
281 return WINSOCK_NOERROR;
282}
283
284//
285/// The ShutDownSocket() function is much like the Winsock shutdown() function. Note
286/// that shutting down a socket essentially means that you can't un-shut it down.
287/// It's a graceful way of preparing to end a session, somewhat like a yellow
288/// stoplight. Use this function to close your socket, while still allowing data be
289/// received from the network. This is as opposed to CloseSocket(), which kills all
290/// transfers in both directions. shutMode is one of the enumerations:
291/// ShutModeNoRecv, ShutModeNoSend, or ShutModeNoRecvSend.
292//
294{
295 if (Handle != static_cast<SOCKET>(INVALID_SOCKET)) {
296 int error = TWinSockDll::shutdown(Handle, shutMode);
297 if (error) {
299 return WINSOCK_ERROR;
300 }
301 Handle = INVALID_SOCKET; // It's invalid now.
302 Bound = false;
303 }
304 return WINSOCK_NOERROR;
305}
306
307//
308/// BindSocket is much like the Winsock bind() function. Regardless of what
309/// mySocketAddress may have been previously, a call to 'bind()' immediately makes
310/// the socket's address the one put into the bind() call. Thus, mySocketAddress is
311/// always assigned to be boundSocketAddress. The address argument must be in
312/// network byte ordering. On the other hand, the SocketAddress class always keeps
313/// its addresses in network byte ordering.
314//
316{
317 SocketAddress = addressToBindTo;
318
319 // bind() ideally returns 0.
320 //
321 if (TWinSockDll::bind(Handle, &SocketAddress, sizeof(sockaddr))) {
323 return WINSOCK_ERROR;
324 }
325 Bound = true;
326 return WINSOCK_NOERROR;
327}
328
329//
330/// This BindSocket simply binds with the previously defined member data socket
331/// address.
332//
334{
335 return BindSocket(SocketAddress);
336}
337
338//
339/// This function stores the address into the reference argument 'socketAddress'.
340/// 'addressLength' will hold the length of the address. 'socket' refers to the
341/// socket whose address will be examined.
342//
347
348//
349/// This function stores the address into the reference argument 'socketAddress'.
350/// 'addressLength' will hold the length of the address. Uses the SOCKET in my
351/// member data as the socket to get the address of.
352//
357
358//
359/// The GetPeerAddress() function is much like the Winsock getpeername() function.
360/// The Winsock getpeername() function is misnamed; it should be getpeeraddress().
361/// socketAddress will be changed to have the right addressing info, and
362/// nAddressLength will be set to be the address length.
363/// Note that this function can be used to get the address for any socket
364/// descriptor, not just our own socket descriptor.
365//
367{
368 // This code only works because SOCKET is defined as a uint and not a struct
369 //
370 if (!socket)
371 socket = Handle;
372
374}
375
376//
377/// This version of GetPeerAddress() works on our own socket descriptor.
378//
383
384//
385/// This may be useful for changing the address or setting the address before
386/// binding. It's no good to change this after binding, as a binding is a permanent
387/// association between a socket descriptor and a full address (for IP, this is a
388/// ushort port and ulong address).
389//
394
395//
396/// The 'myPeerSocketAddress' member variable is useful for Datagram sockets because
397/// it allows them to specify a default destination to send datagrams to. With a
398/// default destination, a datagram socket that always or often sends to one address
399/// can simply call the Write or Send functions with no address arguments and
400/// the data will send to the default address. This function can also be used by a
401/// stream socket to set the address for a peer that it wants to connect to.
402//
407
408#if !defined(__GNUC__) //JJH removal of pragma warn for GCC
409#pragma warn -cln
410#endif
411
412//
413/// GetDriverWaitingSize() is much like calling ioctlsocket(s, FIONREAD,...) in
414/// Winsock. It returns the number of bytes waiting to be read on the socket. For
415/// datagrams, it is the size of the next datagram. For streams, it should be the
416/// total waiting bytes.
417//
419{
422 return 0;
423 }
424 return charsWaiting;
425}
426#if !defined(__GNUC__) //JJH removal of pragma warn for GCC
427#pragma warn .cln
428#endif
429
430//
431/// Returns the total number of bytes waiting to be read.
432//
437
438//
439/// This function gets called whenever the socket gets a read notification. This
440/// means that data on the port is ready to be read. Thus this function must be
441/// subclassed by a DatagramSocket and StreamSocket.
442//
443int TSocket::DoReadNotification(const SOCKET& /*socket*/, int /*nError*/)
444{
445 return 0;
446}
447
448//
449/// The generic socket doesn't know how many bytes it can send, since this limit is
450/// dependent on whether the socket is a stream or datagram socket. Thus this
451/// function must be subclassed by a DatagramSocket and StreamSocket.
452//
453int TSocket::DoWriteNotification(const SOCKET& /*s*/, int /*nError*/)
454{
455 return 0;
456}
457
458//
459/// This isn't responded to in the generic TSocket class.
460//
461int TSocket::DoOOBNotification(const SOCKET& /*s*/, int /*nError*/)
462{
463 return 0;
464}
465
466//
467/// This isn't responded to in the generic TSocket class.
468//
469int TSocket::DoAcceptNotification(const SOCKET& /*s*/, int /*nError*/)
470{
471 return 0;
472}
473
474//
475/// This isn't responded to in the generic TSocket class.
476//
477int TSocket::DoConnectNotification(const SOCKET& /*s*/, int /*nError*/)
478{
479 return 0;
480}
481
482//
483/// This isn't responded to in the generic TSocket class.
484//
485int TSocket::DoCloseNotification(const SOCKET& /*s*/, int /*nError*/)
486{
487 return 0;
488}
489
490//
491/// This should be called by someone who knows what the correct value is.
492//
498
499//
500/// Allows transmission of broadcast messages.
501//
503{
504 // Must pass an int, not a bool, to setsockopt
505 //
508}
509
510//
511/// Records debugging info.
512//
514{
515 // Must pass an BOOL, not a bool, to setsockopt
516 //
517 BOOL bDebug = debug;
518 return SocketsCallCheck(TWinSockDll::setsockopt(Handle, SOL_SOCKET, SO_DEBUG, (char*)&bDebug, sizeof bDebug));
519}
520
521//
522/// If you set 'linger' to true, then that means to linger for 'lingerTime' seconds.
523/// Examples:
524/// - linger=true, lingerTime=0 Hard immediate close. All queued data for sending
525/// gets canned immediately.
526/// - linger=true, lingerTime=2. Graceful close. Waits 2 seconds to try to send any
527/// pending data.
528/// - linger=false, lingerTime=<any>. "Graceful" immediate close. Causes data to be
529/// still in queue to send when ready.
530//
532{
534
535 lingerOptions.l_onoff = linger; //Note that bLinger is a bool and LINGER.l_onoff is a u_short.
536 lingerOptions.l_linger = lingerTime;
537
539}
540
541//
542/// A false argument means don't route.
543//
545{
546 BOOL bRout = !route;
548}
549
550//
551/// Sends keepAlive messages.
552//
558
559//
560/// Receives out-of-band (OOB) data in the normal data stream.
561//
567
568//
569/// Sets the buffer size for receiving messages.
570//
575
576//
577/// Sets the buffer size for sending messages.
578//
583
584//
585/// Allows the socket to bind to an already-bound address.
586//
592
593//
594/// Retrieves the current broadcast option.
595//
597{
599 int size = sizeof bBroadcast;
602 return retval;
603}
604
605//
606/// Retrieves the current debugging option.
607//
609{
610 BOOL bDebug;
611 int size = sizeof bDebug;
613 debug = bDebug != FALSE;
614 return retval;
615}
616
617//
618/// Retreives the current linger option.
619//
621{
623 int size = sizeof lingerOptions;
624
626 linger = lingerOptions.l_onoff;
627 lingerTime = lingerOptions.l_linger;
628 return WINSOCK_NOERROR;
629 }
630 return WINSOCK_ERROR;
631}
632
633//
634/// Retrieves the routing option.
635//
637{
638 BOOL bRoute;
639 int size = sizeof bRoute;
641 // route value of true means "don't route." So we change it to mean what
642 // you'd think.
643 //
644 route = bRoute == FALSE;
645 return WINSOCK_NOERROR;
646 }
647 return WINSOCK_ERROR;
648}
649
650//
651/// Retrieves the keepAlive option.
652//
654{
656 int size = sizeof bKeepAlive;
659 return retval;
660}
661
662//
663/// Retrieves the out-of-band (OOB) option.
664//
673
674//
675/// Retrieves the current receiving buffer size.
676//
682
683//
684/// Retrieves the current sending buffer size.
685//
687{
688 int size = sizeof sendBufferSize;
690}
691
692//
693/// Retrieves the reusable address option.
694//
703
704//----------------------------------------------------------------------------
705
706//
707//
708//
712
713//
714// Default this to be our standard MSG_SOCKET_NOTIFY
715//
716uint TSocketWindow::MsgSocketNotification = MSG_SOCKET_NOTIFY;
717
719:
720 TWindow(0, _T("TSocketWindow")),
721 SocketParent(socketParent),
722 SelectOptions(0),
723 WindowNotification(0),
724 NotificationSet(NotifyAll),
725 LastError(0)
726{
727 Attr.Style = 0; // Turn off WS_CHILD (the default) style.
728}
729
730//
731/// From the user's standpoint, the only thing that is required to make two SocketWindows
732/// act as equal is to make their parents and selection options the same. The actual
733/// window handle identities are unimportant. Thus, we keep our original Window handle,
734/// even if the newSocketWindow had an empty window handle.
735///
736/// However, it may be impossible to assign the parent correctly if this operator is being called
737/// in the parent's operator=(). The new parent SHOULD be the original parent, yet the
738/// newSocketWindow has a new parent. We cannot know in this function the conditions
739/// under which this assignment is called, so we blindly copy the new parent.
740/// The parent will have to override this assignment if the old parent is to
741/// remain as it was.
742///
743/// This function does the best it can to make this window act just like newSocketWindow:
744//
746{
747 SelectOptions = src.SelectOptions;
748 SocketParent = src.SocketParent;
749 WindowNotification = src.WindowNotification;
750 NotificationSet = src.NotificationSet;
751 LastError = src.LastError;
752
753 if (SocketParent->Handle) {
754 // Note that if SelectOptions were empty (0), then we are saying to turn
755 // off notifications and make the socket blocking.
756 //
757 TWinSockDll::WSAAsyncSelect(SocketParent->Handle, *this, MSG_SOCKET_NOTIFY, SelectOptions);
758 }
759 return *this;
760}
761
762//
763/// This function says to only listen to FD_ACCEPT messages. It is important to note that a
764/// socket set up to be a listening socket will never be a connected socket, and a connected
765/// socket will never receive FD_ACCEPT messages. Thus all stream sockets are implicitly either
766/// connected sockets or listening sockets.
767///
768/// Since the accepted socket will want to have a different notification window than the
769/// listening socket, and the sockets specification says that an accepted socket
770/// inherits the notification properties of the listening socket, it is imperative
771/// that the listening socket not be set to receive FD_READ, etc notifications. This
772/// is because it is possible that between the accept() call for the new socket and
773/// the WSAAsyncSelect() call for the new socket, data may be received for the new socket.
774/// Thus the listening socket may get sent the message and it would never get routed to
775/// the new socket.
776///
777/// Calling this function is saying that this SocketWindow is for listening for connections.
778///
779/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine GetLastError().
780//
786
787//
788/// This function turns on all Winsock notifications except FD_ACCEPT.
789///
790/// Calling this function is saying that this SocketWindow is for connections rather
791/// than for listening. Since a Winsock socket cannot be a listening socket and
792/// a connected socket at the same time, we have serarate the notification functions
793/// from each other: StartAcceptNotification() and StartRegularNotification().
794///
795/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
796/// GetLastError().
797//
803
804//
805/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine
806/// GetLastError().
807//
819
820//
821/// CancelNotification() turns off the notification to this window. This also changes the
822/// socket to be blocking.
823/// The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine GetLastError().
824//
830
831//
832/// DoNotification() is the SocketWindow's protected internal notification system.
833//
835{
836 SOCKET socket = param1;
838
839 if (socket != SocketParent->Handle)
840 return 0;
841
842 switch (WSAGETSELECTEVENT(param2)) {
843 case FD_READ:
845 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
846 }
847 SocketParent->DoReadNotification(socket, error);
848 break;
849 case FD_WRITE:
851 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
852 }
853 SocketParent->DoWriteNotification(socket, error);
854 break;
855 case FD_OOB:
857 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
858 }
859 SocketParent->DoOOBNotification(socket, error);
860 break;
861 case FD_ACCEPT:
863 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
864 }
865 SocketParent->DoAcceptNotification(socket, error);
866 break;
867 case FD_CONNECT:
869 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
870 }
871 SocketParent->DoConnectNotification(socket, error);
872 break;
873 case FD_CLOSE:
875 return WindowNotification->SendMessage(MsgSocketNotification, param1, param2);
876 }
877 SocketParent->DoCloseNotification(socket, error);
878 }
879 return 1;
880}
881
882} // OWL namespace
883/* ========================================================================== */
884
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 GetReuseAddressOption(bool &bAllowReuseAddress)
Retrieves the reusable address option.
Definition wsksock.cpp:695
int SetKeepAliveOption(bool bKeepAlive)
Sends keepAlive messages.
Definition wsksock.cpp:553
int LastError
Last Error.
Definition wsksock.h:206
virtual void SetMaxReadBufferSize(int nNewMaxReadBufferSize)
This should be called by someone who knows what the correct value is.
Definition wsksock.cpp:493
int GetOOBOption(bool &bSendOOBDataInline)
Retrieves the out-of-band (OOB) option.
Definition wsksock.cpp:665
virtual ulong GetTotalWaitingSize()
Returns the total number of bytes waiting to be read.
Definition wsksock.cpp:433
int SetOOBOption(bool bSendOOBDataInline)
Receives out-of-band (OOB) data in the normal data stream.
Definition wsksock.cpp:562
virtual int DoCloseNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
Definition wsksock.cpp:485
int SetDebugOption(bool bDebug)
Records debugging info.
Definition wsksock.cpp:513
virtual int DoReadNotification(const SOCKET &s, int nError)
This function gets called whenever the socket gets a read notification.
Definition wsksock.cpp:443
virtual int DoConnectNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
Definition wsksock.cpp:477
virtual int ConvertProtocol(char *protocol)
Converts a string protocol to integer value.
Definition wsksock.cpp:243
virtual int CreateSocket()
The CreateSocket function is much like the Winsock socket() function.
Definition wsksock.cpp:261
virtual int CloseSocket()
The CloseSocket() function is much like the Winsock closesocket() function.
Definition wsksock.cpp:270
virtual int BindSocket()
binds to our address
Definition wsksock.cpp:333
virtual int GetPeerAddress(TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket)
The GetPeerAddress() function is much like the Winsock getpeername() function.
Definition wsksock.cpp:366
virtual int ShutDownSocket(TShutMode shutMode=ShutModeNoRecvSend)
The ShutDownSocket() function is much like the Winsock shutdown() function.
Definition wsksock.cpp:293
virtual int DoAcceptNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
Definition wsksock.cpp:469
int SetSendBufferOption(int nSendBufferSize)
Sets the buffer size for sending messages.
Definition wsksock.cpp:579
int SetReceiveBufferOption(int nReceiveBufferSize)
Sets the buffer size for receiving messages.
Definition wsksock.cpp:571
virtual int StartRegularNotification()
This function turns on all Winsock notifications except FD_ACCEPT.
Definition wsksock.cpp:190
TSocket & operator=(TSocket &newSocket)
Definition wsksock.cpp:120
int GetBroadcastOption(bool &bBroadcast)
Retrieves the current broadcast option.
Definition wsksock.cpp:596
int Protocol
IPPROTO_TCP, etc.
Definition wsksock.h:205
int SetBroadcastOption(bool bBroadcast)
Allows transmission of broadcast messages.
Definition wsksock.cpp:502
virtual int GetMyAddress(TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket)
This function stores the address into the reference argument 'socketAddress'.
Definition wsksock.cpp:343
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 SetReuseAddressOption(bool bAllowReuseAddress)
Allows the socket to bind to an already-bound address.
Definition wsksock.cpp:587
int GetKeepAliveOption(bool &bKeepAlive)
Retrieves the keepAlive option.
Definition wsksock.cpp:653
TSocket()
Default constructor for a socket.
Definition wsksock.cpp:21
int SocketsCallCheck(int error)
Checks the return error value from a sockets call, caching the last error if one occured (i....
Definition wsksock.cpp:108
virtual int DoWriteNotification(const SOCKET &s, int nError)
The generic socket doesn't know how many bytes it can send, since this limit is dependent on whether ...
Definition wsksock.cpp:453
virtual ~TSocket()
This TSocket destructor will close the socket it if has not be closed already.
Definition wsksock.cpp:79
virtual int StartCustomNotification(int nSelectionOptions)
The return value is WINSOCK_ERROR or WINSOCK_NOERROR.
Definition wsksock.cpp:203
void Init()
This function is an intitialization function called by the TSocket constructors.
Definition wsksock.cpp:92
int GetSendBufferOption(int &nSendBufferSize)
Retrieves the current sending buffer size.
Definition wsksock.cpp:686
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 GetLingerOption(bool &bLinger, ushort &nLingerTime)
Retreives the current linger option.
Definition wsksock.cpp:620
virtual ulong GetDriverWaitingSize()
GetDriverWaitingSize() is much like calling ioctlsocket(s, FIONREAD,...) in Winsock.
Definition wsksock.cpp:418
virtual int CancelNotification()
CancelNotification() turns off the notification to this window.
Definition wsksock.cpp:218
int GetReceiveBufferOption(int &nReceiveBufferSize)
Retrieves the current receiving buffer size.
Definition wsksock.cpp:677
int GetDebugOption(bool &bDebug)
Retrieves the current debugging option.
Definition wsksock.cpp:608
int MaxReadBufferSize
Maximum buffer size.
Definition wsksock.h:207
int SetRouteOption(bool bRoute)
A false argument means don't route.
Definition wsksock.cpp:544
virtual void SetMyAddress(TSocketAddress &newSocketAddress)
This may be useful for changing the address or setting the address before binding.
Definition wsksock.cpp:390
virtual int DoOOBNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
Definition wsksock.cpp:461
virtual void SetSocketStyle(int nNewFamily=PF_INET, int nNewType=SOCK_STREAM, int nNewProtocol=0)
The SetSocketStyle function can be used to set or change some TSocket member data.
Definition wsksock.cpp:232
int GetRouteOption(bool &bRoute)
Retrieves the routing option.
Definition wsksock.cpp:636
virtual int StartAcceptNotification()
This function says to listen only to FD_ACCEPT messages.
Definition wsksock.cpp:171
int SetLingerOption(bool bLinger, ushort nLingerTime=0)
If you set 'linger' to true, then that means to linger for 'lingerTime' seconds.
Definition wsksock.cpp:531
virtual void SetPeerSocketAddress(TSocketAddress &newPeerSocketAddress)
The 'myPeerSocketAddress' member variable is useful for Datagram sockets because it allows them to sp...
Definition wsksock.cpp:403
Derived from TWindow, a private window used to catch notification messages.
Definition wsksock.h:63
int StartRegularNotification()
This function turns on all Winsock notifications except FD_ACCEPT.
Definition wsksock.cpp:798
TWindow * WindowNotification
A second window that can be notified instead of the Socket.
Definition wsksock.h:86
TResult DoNotification(TParam1, TParam2)
DoNotification() is the SocketWindow's protected internal notification system.
Definition wsksock.cpp:834
int GetLastError()
Return the last error on the socket.
Definition wsksock.h:239
TSocketWindow & operator=(TSocketWindow &src)
From the user's standpoint, the only thing that is required to make two SocketWindows act as equal is...
Definition wsksock.cpp:745
int LastError
Last error.
Definition wsksock.h:88
void SetSocketParent(TSocket *socket)
Definition wsksock.h:267
int StartAcceptNotification()
This function says to only listen to FD_ACCEPT messages.
Definition wsksock.cpp:781
int CancelNotification()
CancelNotification() turns off the notification to this window.
Definition wsksock.cpp:825
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
int StartCustomNotification(int selectOptions)
The return value is WINSOCK_ERROR or WINSOCK_NOERROR.
Definition wsksock.cpp:808
static int getpeername(SOCKET s, struct sockaddr *name, int *nameLen)
Definition winsock.cpp:64
static int getsockname(SOCKET s, struct sockaddr *name, int *nameLen)
Definition winsock.cpp:72
static int ioctlsocket(SOCKET s, long cmd, ulong *argp)
Definition winsock.cpp:116
static int setsockopt(SOCKET s, int level, int optName, LPCSTR optVal, int optLen)
Definition winsock.cpp:187
static int shutdown(SOCKET s, int how)
Definition winsock.cpp:196
static SOCKET socket(int af, int type, int protocol)
Definition winsock.cpp:203
static int WSAGetLastError(void)
Definition winsock.cpp:294
static int closesocket(SOCKET s)
Definition winsock.cpp:49
static int bind(SOCKET s, struct sockaddr *addr, int nameLen)
Definition winsock.cpp:41
static int getsockopt(SOCKET s, int level, int optName, char *optVal, int *optLen)
Definition winsock.cpp:80
static int WSAAsyncSelect(SOCKET s, HWND hWnd, uint msg, long event)
Definition winsock.cpp:392
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
int operator==(const TBitSet< T > &bs1, const TBitSet< T > &bs2)
Definition bitset.h:86
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
@ 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
@ 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
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define EV_MESSAGE(message, method)
Response table entry for raw message handling Uses a dispatcher that just forwards WPARAM and LPARAM.
Definition windowev.h:113
Main header of the Winsock OWL subsystem.
#define WINSOCK_NOERROR
Definition wskhostm.h:30
#define WINSOCK_ERROR
Definition wskhostm.h:31
#define N_DEF_MAX_READ_BUFFFER_SIZE
Definition wsksock.h:27
#define FD_ALL
Definition wsksock.h:33
#define MSG_SOCKET_NOTIFY
User-defined message used for socked notifications.
Definition wsksock.h:32