23 Handle(INVALID_SOCKET),
50 Family = SocketAddress.sa_family;
61 Handle(INVALID_SOCKET),
63 SocketAddress(newSocketAddress),
81 if (Handle !=
static_cast<SOCKET
>(INVALID_SOCKET) && !
SaveSocket) {
126 Handle = newSocket.Handle;
127 SocketAddress = newSocket.SocketAddress;
128 PeerSocketAddress = newSocket.PeerSocketAddress;
151 return socket1.Handle == socket2.Handle && socket1.
Window == socket2.
Window;
247 if (strcmp(
"tcp", protocol) == 0)
249 if(strcmp(
"udp", protocol) == 0)
272 if (Handle !=
static_cast<SOCKET
>(INVALID_SOCKET)) {
279 Handle = INVALID_SOCKET;
295 if (Handle !=
static_cast<SOCKET
>(INVALID_SOCKET)) {
301 Handle = INVALID_SOCKET;
317 SocketAddress = addressToBindTo;
355 return GetMyAddress(socketAddress, addressLength, Handle);
392 SocketAddress = newSocketAddress;
405 PeerSocketAddress = newPeerSocketAddress;
408#if !defined(__GNUC__)
426#if !defined(__GNUC__)
495 if(maxReadBufferSize > 0)
506 BOOL bcast = broadcast;
533 LINGER lingerOptions;
535 lingerOptions.l_onoff = linger;
536 lingerOptions.l_linger = lingerTime;
555 BOOL bKeepAlive = keepAlive;
564 BOOL bSendOOBDataInline = sendOOBDataInline;
589 BOOL bAllowReuseAddress = allowReuseAddress;
599 int size =
sizeof bBroadcast;
601 broadcast = bBroadcast != FALSE;
611 int size =
sizeof bDebug;
613 debug = bDebug != FALSE;
622 LINGER lingerOptions;
623 int size =
sizeof lingerOptions;
626 linger = lingerOptions.l_onoff;
627 lingerTime = lingerOptions.l_linger;
639 int size =
sizeof bRoute;
644 route = bRoute == FALSE;
656 int size =
sizeof bKeepAlive;
658 keepAlive = bKeepAlive != FALSE;
667 BOOL bSendOOBDataInline;
668 int size =
sizeof bSendOOBDataInline;
670 sendOOBDataInline = bSendOOBDataInline != FALSE;
679 int size =
sizeof receiveBufferSize;
688 int size =
sizeof sendBufferSize;
697 BOOL bAllowReuseAddress;
698 int size =
sizeof bAllowReuseAddress;
700 allowReuseAddress = bAllowReuseAddress != FALSE;
721 SocketParent(socketParent),
748 SocketParent = src.SocketParent;
753 if (SocketParent->Handle) {
836 SOCKET socket = param1;
837 int error = (int)WSAGETSELECTERROR(param2);
839 if (socket != SocketParent->Handle)
842 switch (WSAGETSELECTEVENT(param2)) {
847 SocketParent->DoReadNotification(socket, error);
853 SocketParent->DoWriteNotification(socket, error);
859 SocketParent->DoOOBNotification(socket, error);
865 SocketParent->DoAcceptNotification(socket, error);
871 SocketParent->DoConnectNotification(socket, error);
877 SocketParent->DoCloseNotification(socket, error);
The TSocketAddress class stores a Winsock socket address.
TSocket encapsulates the basic attributes of a socket.
int GetReuseAddressOption(bool &bAllowReuseAddress)
Retrieves the reusable address option.
int SetKeepAliveOption(bool bKeepAlive)
Sends keepAlive messages.
virtual void SetMaxReadBufferSize(int nNewMaxReadBufferSize)
This should be called by someone who knows what the correct value is.
int GetOOBOption(bool &bSendOOBDataInline)
Retrieves the out-of-band (OOB) option.
virtual ulong GetTotalWaitingSize()
Returns the total number of bytes waiting to be read.
int SetOOBOption(bool bSendOOBDataInline)
Receives out-of-band (OOB) data in the normal data stream.
virtual int DoCloseNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
int SetDebugOption(bool bDebug)
Records debugging info.
virtual int DoReadNotification(const SOCKET &s, int nError)
This function gets called whenever the socket gets a read notification.
virtual int DoConnectNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
virtual int ConvertProtocol(char *protocol)
Converts a string protocol to integer value.
virtual int CreateSocket()
The CreateSocket function is much like the Winsock socket() function.
virtual int CloseSocket()
The CloseSocket() function is much like the Winsock closesocket() function.
virtual int BindSocket()
binds to our address
virtual int GetPeerAddress(TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket)
The GetPeerAddress() function is much like the Winsock getpeername() function.
virtual int ShutDownSocket(TShutMode shutMode=ShutModeNoRecvSend)
The ShutDownSocket() function is much like the Winsock shutdown() function.
virtual int DoAcceptNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
int SetSendBufferOption(int nSendBufferSize)
Sets the buffer size for sending messages.
int SetReceiveBufferOption(int nReceiveBufferSize)
Sets the buffer size for receiving messages.
virtual int StartRegularNotification()
This function turns on all Winsock notifications except FD_ACCEPT.
TSocket & operator=(TSocket &newSocket)
int GetBroadcastOption(bool &bBroadcast)
Retrieves the current broadcast option.
int Protocol
IPPROTO_TCP, etc.
int SetBroadcastOption(bool bBroadcast)
Allows transmission of broadcast messages.
virtual int GetMyAddress(TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket)
This function stores the address into the reference argument 'socketAddress'.
short SaveSocket
Save the socket on deletion?
TSocketWindow Window
Will receive internal notifications and pass them to this class.
int Type
SOCK_STREAM, etc.
int SetReuseAddressOption(bool bAllowReuseAddress)
Allows the socket to bind to an already-bound address.
int GetKeepAliveOption(bool &bKeepAlive)
Retrieves the keepAlive option.
TSocket()
Default constructor for a socket.
int SocketsCallCheck(int error)
Checks the return error value from a sockets call, caching the last error if one occured (i....
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 ...
virtual ~TSocket()
This TSocket destructor will close the socket it if has not be closed already.
virtual int StartCustomNotification(int nSelectionOptions)
The return value is WINSOCK_ERROR or WINSOCK_NOERROR.
void Init()
This function is an intitialization function called by the TSocket constructors.
int GetSendBufferOption(int &nSendBufferSize)
Retrieves the current sending buffer size.
int Family
PF_INET, etc. (this is the protocol family).
TShutMode
How to shutdown the socket.
int GetLingerOption(bool &bLinger, ushort &nLingerTime)
Retreives the current linger option.
virtual ulong GetDriverWaitingSize()
GetDriverWaitingSize() is much like calling ioctlsocket(s, FIONREAD,...) in Winsock.
virtual int CancelNotification()
CancelNotification() turns off the notification to this window.
int GetReceiveBufferOption(int &nReceiveBufferSize)
Retrieves the current receiving buffer size.
virtual int BindSocket(const TSocketAddress &addressToBindTo)
binds to a given address
int GetDebugOption(bool &bDebug)
Retrieves the current debugging option.
int MaxReadBufferSize
Maximum buffer size.
int SetRouteOption(bool bRoute)
A false argument means don't route.
virtual void SetMyAddress(TSocketAddress &newSocketAddress)
This may be useful for changing the address or setting the address before binding.
virtual int DoOOBNotification(const SOCKET &s, int nError)
This isn't responded to in the generic TSocket class.
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.
int GetRouteOption(bool &bRoute)
Retrieves the routing option.
virtual int StartAcceptNotification()
This function says to listen only to FD_ACCEPT messages.
int SetLingerOption(bool bLinger, ushort nLingerTime=0)
If you set 'linger' to true, then that means to linger for 'lingerTime' seconds.
virtual void SetPeerSocketAddress(TSocketAddress &newPeerSocketAddress)
The 'myPeerSocketAddress' member variable is useful for Datagram sockets because it allows them to sp...
Derived from TWindow, a private window used to catch notification messages.
int StartRegularNotification()
This function turns on all Winsock notifications except FD_ACCEPT.
TWindow * WindowNotification
A second window that can be notified instead of the Socket.
TResult DoNotification(TParam1, TParam2)
DoNotification() is the SocketWindow's protected internal notification system.
int GetLastError()
Return the last error on the socket.
TSocketWindow & operator=(TSocketWindow &src)
From the user's standpoint, the only thing that is required to make two SocketWindows act as equal is...
void SetSocketParent(TSocket *socket)
int StartAcceptNotification()
This function says to only listen to FD_ACCEPT messages.
int CancelNotification()
CancelNotification() turns off the notification to this window.
int NotificationSet
Types of notification to respond to.
int SelectOptions
We need to keep our own copy of this so we can do an assignment operator.
TSocketWindow(TSocket *socketParent)
int StartCustomNotification(int selectOptions)
The return value is WINSOCK_ERROR or WINSOCK_NOERROR.
static int getpeername(SOCKET s, struct sockaddr *name, int *nameLen)
static int getsockname(SOCKET s, struct sockaddr *name, int *nameLen)
static int ioctlsocket(SOCKET s, long cmd, ulong *argp)
static int setsockopt(SOCKET s, int level, int optName, LPCSTR optVal, int optLen)
static int shutdown(SOCKET s, int how)
static SOCKET socket(int af, int type, int protocol)
static int WSAGetLastError(void)
static int closesocket(SOCKET s)
static int bind(SOCKET s, struct sockaddr *addr, int nameLen)
static int getsockopt(SOCKET s, int level, int optName, char *optVal, int *optLen)
static int WSAAsyncSelect(SOCKET s, HWND hWnd, uint msg, long event)
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
int operator==(const TBitSet< T > &bs1, const TBitSet< T > &bs2)
Object Windows Library (OWLNext Core).
@ NotifyRead
Notification of readiness for reading.
@ NotifyAccept
Notification of incoming connections.
@ NotifyOOB
Notification of the arrival of out-of-band data.
@ NotifyWrite
Notification of readiness for writing.
@ NotifyClose
Notification of socket closure.
@ NotifyAll
All notifications.
@ NotifyConnect
Notification of completed connection.
LPARAM TParam2
Second parameter type.
WPARAM TParam1
First parameter type.
LRESULT TResult
Result type.
EV_MESSAGE(BM_SETSTYLE, BMSetStyle)
General definitions used by all ObjectWindows programs.
Main header of the Winsock OWL subsystem.
#define N_DEF_MAX_READ_BUFFFER_SIZE
#define MSG_SOCKET_NOTIFY
User-defined message used for socked notifications.