/////////////////////////////////////////////////////////////////////////////
// Name: socket.h
-// Purpose: documentation for wxIPV4address class
+// Purpose: interface of wxIPV4address
// Author: wxWidgets team
// RCS-ID: $Id$
// Licence: wxWindows license
as this correctly handles multi-homed hosts and avoids other small
problems. Internally, this is the same as setting the IP address
to @b INADDR_ANY.
-
+
@returns Returns @true on success, @false if something went wrong.
*/
bool AnyAddress();
};
+
/**
@class wxSocketServer
@wxheader{socket.h}
@library{wxnet}
@category{net}
- @seealso
- wxSocketServer::WaitForAccept, wxSocketBase::SetNotify, wxSocketBase::Notify,
- wxSocketServer::AcceptWith
+ @see wxSocketServer::WaitForAccept, wxSocketBase::SetNotify,
+ wxSocketBase::Notify, wxSocketServer::AcceptWith
*/
class wxSocketServer : public wxSocketBase
{
Constructs a new server and tries to bind to the specified @e address.
Before trying to accept new connections, test whether it succeeded with
@ref wxSocketBase::isok wxSocketBase:IsOk.
-
+
@param address
Specifies the local address for the server (e.g. port number).
@param flags
incoming connections with WaitForAccept()
or catch @b wxSOCKET_CONNECTION events, then call Accept once you know
that there is an incoming connection waiting to be accepted.
-
+
@returns Returns an opened socket connection, or @NULL if an error
occurred or if the wait parameter was @false and there
were no pending connections.
-
+
@see WaitForAccept(), wxSocketBase::SetNotify,
wxSocketBase::Notify, AcceptWith()
*/
/**
Accept an incoming connection using the specified socket object.
-
+
@param socket
Socket to be initialized
-
+
@returns Returns @true on success, or @false if an error occurred or if the
wait parameter was @false and there were no pending
connections.
Accept() or AcceptWith()
with @e wait set to @false, to detect when an incoming connection is waiting
to be accepted.
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns Returns @true if an incoming connection arrived, @false if the
timeout elapsed.
*/
};
+
/**
@class wxIPaddress
@wxheader{socket.h}
to @b INADDR_ANY.
On IPV4 implementations, 0.0.0.0
On IPV6 implementations, ::
-
+
@returns Returns @true on success, @false if something went wrong.
*/
virtual bool AnyAddress();
Internally, this is the same as setting the IP address
to @b INADDR_BROADCAST.
On IPV4 implementations, 255.255.255.255
-
+
@returns Returns @true on success, @false if something went wrong.
*/
virtual bool BroadcastAddress();
Set address to localhost.
On IPV4 implementations, 127.0.0.1
On IPV6 implementations, ::1
-
+
@returns Returns @true on success, @false if something went wrong.
*/
virtual bool LocalHost();
};
+
/**
@class wxSocketClient
@wxheader{socket.h}
@library{wxnet}
@category{net}
- @seealso
- wxSocketClient::WaitOnConnect, wxSocketBase::SetNotify, wxSocketBase::Notify
+ @see wxSocketClient::WaitOnConnect, wxSocketBase::SetNotify,
+ wxSocketBase::Notify
*/
class wxSocketClient : public wxSocketBase
{
public:
/**
Constructor.
-
+
@param flags
Socket flags (See wxSocketBase::SetFlags)
*/
To detect this, use WaitOnConnect(),
or catch @b wxSOCKET_CONNECTION events (for successful establishment)
and @b wxSOCKET_LOST events (for connection failure).
-
+
@param address
Address of the server.
@param local
and then using the 2-parameter Connect method.
@param wait
If @true, waits for the connection to complete.
-
+
@returns Returns @true if the connection is established and no error
occurs.
-
+
@see WaitOnConnect(), wxSocketBase::SetNotify,
wxSocketBase::Notify
*/
Wait until a connection request completes, or until the specified timeout
elapses. Use this function after issuing a call
to Connect() with @e wait set to @false.
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns WaitOnConnect returns @true if the connection request completes.
This does not necessarily mean that the connection was
successfully established; it might also happen that the
};
+
/**
@class wxSockAddress
@wxheader{socket.h}
@library{wxbase}
@category{FIXME}
- @seealso
- wxSocketBase, wxIPaddress, wxIPV4address
+ @see wxSocketBase, wxIPaddress, wxIPV4address
*/
class wxSockAddress : public wxObject
{
};
+
/**
@class wxSocketEvent
@wxheader{socket.h}
@library{wxnet}
@category{net}
- @seealso
- wxSocketBase, wxSocketClient, wxSocketServer
+ @see wxSocketBase, wxSocketClient, wxSocketServer
*/
class wxSocketEvent : public wxEvent
{
Returns the socket object to which this event refers to. This makes
it possible to use the same event handler for different sockets.
*/
- wxSocketBase* GetSocket();
+ wxSocketBase* GetSocket() const;
/**
Returns the socket event type.
*/
- wxSocketNotify GetSocketEvent();
+ wxSocketNotify GetSocketEvent() const;
};
+
/**
@class wxSocketBase
@wxheader{socket.h}
@library{wxnet}
@category{net}
- @seealso
- wxSocketEvent, wxSocketClient, wxSocketServer, @ref overview_samplesockets
+ @see wxSocketEvent, wxSocketClient, wxSocketServer, @ref overview_samplesockets
"Sockets sample"
*/
class wxSocketBase : public wxObject
/**
Functions that perform basic IO functionality.
Close()
-
+
Discard()
-
+
Peek()
-
+
Read()
-
+
ReadMsg()
-
+
Unread()
-
+
Write()
-
+
WriteMsg()
Functions that perform a timed wait on a certain IO condition.
InterruptWait()
-
+
Wait()
-
+
WaitForLost()
-
+
WaitForRead()
-
+
WaitForWrite()
-
+
and also:
wxSocketServer::WaitForAccept
-
+
wxSocketClient::WaitOnConnect
Functions that allow applications to customize socket IO as needed.
GetFlags()
-
+
SetFlags()
-
+
SetTimeout()
-
+
SetLocal()
*/
/**
@ref construct() wxSocketBase
-
+
@ref destruct() ~wxSocketBase
-
+
Destroy()
*/
events have been processed. For the same reason, you should avoid creating
socket objects in the stack.
Destroy calls Close() automatically.
-
+
@returns Always @true.
*/
bool Destroy();
Use this function to check for an error condition after one of the
following calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg.
*/
- bool Error();
+ bool Error() const;
/**
Returns a pointer of the client data for this socket, as set with
SetClientData()
*/
- void* GetClientData();
+ void* GetClientData() const;
/**
Returns current IO flags, as set with SetFlags()
*/
- wxSocketFlags GetFlags();
+ wxSocketFlags GetFlags() const;
/**
This function returns the local address field of the socket. The local
address field contains the complete local address of the socket (local
address, local port, ...).
-
+
@returns @true if no error happened, @false otherwise.
*/
- bool GetLocal(wxSockAddress& addr);
+ bool GetLocal(wxSockAddress& addr) const;
/**
This function returns the peer address field of the socket. The peer
address field contains the complete peer host address of the socket
(address, port, ...).
-
+
@returns @true if no error happened, @false otherwise.
*/
- bool GetPeer(wxSockAddress& addr);
+ bool GetPeer(wxSockAddress& addr) const;
/**
Functions that allow applications to receive socket events.
Notify()
-
+
SetNotify()
-
+
GetClientData()
-
+
SetClientData()
-
+
SetEventHandler()
*/
/**
Returns @true if the socket is connected.
*/
- bool IsConnected();
+ bool IsConnected() const;
/**
This function waits until the socket is readable. This might mean that
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
*/
- bool IsData();
+ bool IsData() const;
/**
Returns @true if the socket is not connected.
*/
- bool IsDisconnected();
+ bool IsDisconnected() const;
/**
Returns @true if the socket is initialized and ready and @false in other
cases.
*/
- bool IsOk();
+ bool IsOk() const;
/**
Returns the number of bytes read or written by the last IO call.
after using one of the following IO calls: Discard, Peek, Read,
ReadMsg, Unread, Write, WriteMsg.
*/
- wxUint32 LastCount();
+ wxUint32 LastCount() const;
/**
Returns the last wxSocket error. See @ref overview_wxsocketbase "wxSocket
if the last IO call failed. If this returns @true, use LastError
to discover the cause of the error.
*/
- wxSocketError LastError();
+ wxSocketError LastError() const;
/**
According to the @a notify value, this function enables
Peeking a buffer doesn't delete it from the socket input queue.
Use LastCount() to verify the number of bytes actually peeked.
Use Error() to determine if the operation succeeded.
-
+
@param buffer
Buffer where to put peeked data.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object.
-
+
@see Error(), LastError(), LastCount(),
SetFlags()
*/
This function reads a buffer of @a nbytes bytes from the socket.
Use LastCount() to verify the number of bytes actually read.
Use Error() to determine if the operation succeeded.
-
+
@param buffer
Buffer where to put read data.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object.
-
+
@see Error(), LastError(), LastCount(),
SetFlags()
*/
buffer to be entirely filled, unless an error occurs.
Use LastCount() to verify the number of bytes actually read.
Use Error() to determine if the operation succeeded.
-
+
@param buffer
Buffer where to put read data.
@param nbytes
Size of the buffer.
-
+
@returns Returns a reference to the current object.
-
+
@see Error(), LastError(), LastCount(),
SetFlags(), WriteMsg()
*/
This function restores the previous state of the socket, as saved
with SaveState()
Calls to SaveState and RestoreState can be nested.
-
+
@see SaveState()
*/
void RestoreState();
Notify(), user data, as set with
SetClientData().
Calls to SaveState and RestoreState can be nested.
-
+
@see RestoreState()
*/
void SaveState();
handler will be called for those events for which notification is
enabled with SetNotify() and
Notify().
-
+
@param handler
Specifies the event handler you want to use.
@param id
The id of socket event.
-
+
@see SetNotify(), Notify(), wxSocketEvent, wxEvtHandler
*/
void SetEventHandler(wxEvtHandler& handler, int id = -1);
Use SetFlags to customize IO operation for this socket.
The @a flags parameter may be a combination of flags ORed together.
The following flags can be used:
-
+
@b wxSOCKET_NONE
-
+
Normal functionality.
-
+
@b wxSOCKET_NOWAIT
-
+
Read/write as much data as possible and return immediately.
-
+
@b wxSOCKET_WAITALL
-
+
Wait for all required data to be read/written unless an error occurs.
-
+
@b wxSOCKET_BLOCK
-
+
Block the GUI (do not yield) while reading/writing data.
-
+
@b wxSOCKET_REUSEADDR
-
+
Allows the use of an in-use port (wxServerSocket only)
-
+
@b wxSOCKET_BROADCAST
-
+
Switches the socket to broadcast mode
-
+
@b wxSOCKET_NOBIND
-
+
Stops the socket from being bound to a specific adapter (normally used in
conjunction with @b wxSOCKET_BROADCAST)
-
+
A brief overview on how to use these flags follows.
If no flag is specified (this is the same as @b wxSOCKET_NONE),
IO calls will return after some data has been read or written, even
SetNotify specifies which socket events are to be sent to the event handler.
The @a flags parameter may be combination of flags ORed together. The
following flags can be used:
-
+
@b wxSOCKET_INPUT_FLAG
-
+
to receive wxSOCKET_INPUT
-
+
@b wxSOCKET_OUTPUT_FLAG
-
+
to receive wxSOCKET_OUTPUT
-
+
@b wxSOCKET_CONNECTION_FLAG
-
+
to receive wxSOCKET_CONNECTION
-
+
@b wxSOCKET_LOST_FLAG
-
+
to receive wxSOCKET_LOST
-
+
For example:
-
+
In this example, the user will be notified about incoming socket data and
whenever the connection is closed.
For more information on socket events see @ref overview_wxsocketbase "wxSocket
/**
Functions to retrieve current state and miscellaneous info.
Error()
-
+
GetLocal()
-
+
GetPeer()
IsConnected()
-
+
IsData()
-
+
IsDisconnected()
-
+
LastCount()
-
+
LastError()
-
+
IsOk()
-
+
SaveState()
-
+
RestoreState()
*/
in the incoming queue. This function is not affected by wxSocket flags.
If you use LastCount(), it will always return @e nbytes.
If you use Error(), it will always return @false.
-
+
@param buffer
Buffer to be unread.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object.
-
+
@see Error(), LastCount(), LastError()
*/
wxSocketBase Unread(const void* buffer, wxUint32 nbytes);
/**
This function waits until any of the following conditions is @true:
-
+
The socket becomes readable.
The socket becomes writable.
An ongoing connection request has completed (wxSocketClient only)
The connection has been closed.
Note that it is recommended to use the individual Wait functions
to wait for the required condition, instead of this one.
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns Returns @true when any of the above conditions is satisfied,
@false if the timeout was reached.
-
+
@see InterruptWait(), wxSocketServer::WaitForAccept,
WaitForLost(), WaitForRead(),
WaitForWrite(), wxSocketClient::WaitOnConnect
/**
This function waits until the connection is lost. This may happen if
the peer gracefully closes the connection or if the connection breaks.
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns Returns @true if the connection was lost, @false if the timeout
was reached.
-
+
@see InterruptWait(), Wait()
*/
- bool Wait(long seconds = -1, long millisecond = 0);
+ bool WaitForLost(long seconds = -1, long millisecond = 0);
/**
This function waits until the socket is readable. This might mean that
the connection has been closed, so that a read operation will complete
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns Returns @true if the socket becomes readable, @false on timeout.
-
+
@see InterruptWait(), Wait()
*/
bool WaitForRead(long seconds = -1, long millisecond = 0);
connection has been closed, so that a write operation is guaranteed to
complete immediately (unless the @b wxSOCKET_WAITALL flag is set,
in which case the operation might still block).
-
+
@param seconds
Number of seconds to wait.
If -1, it will wait for the default timeout,
as set with SetTimeout.
@param millisecond
Number of milliseconds to wait.
-
+
@returns Returns @true if the socket becomes writable, @false on timeout.
-
+
@see InterruptWait(), Wait()
*/
bool WaitForWrite(long seconds = -1, long millisecond = 0);
This function writes a buffer of @a nbytes bytes to the socket.
Use LastCount() to verify the number of bytes actually written.
Use Error() to determine if the operation succeeded.
-
+
@param buffer
Buffer with the data to be sent.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object.
-
+
@see Error(), LastError(), LastCount(),
SetFlags()
*/
buffer to be sent, unless an error occurs.
Use LastCount() to verify the number of bytes actually written.
Use Error() to determine if the operation succeeded.
-
+
@param buffer
Buffer with the data to be sent.
@param nbytes
Number of bytes to send.
-
+
@returns Returns a reference to the current object.
*/
wxSocketBase WriteMsg(const void* buffer, wxUint32 nbytes);
};
+
/**
@class wxDatagramSocket
@wxheader{socket.h}
@library{wxnet}
@category{FIXME}
- @seealso
- wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
+ @see wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
wxSocketBase::SetFlags,
*/
class wxDatagramSocket : public wxSocketBase
public:
/**
Constructor.
-
+
@param flags
Socket flags (See wxSocketBase::SetFlags)
*/
This function reads a buffer of @a nbytes bytes from the socket.
Use wxSocketBase::LastCount to verify the number of bytes actually read.
Use wxSocketBase::Error to determine if the operation succeeded.
-
+
@param address
Any address - will be overwritten with the address of the peer that sent
that data.
Buffer where to put read data.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object, and the address of
the peer that sent the data on address param.
-
+
@see wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
wxSocketBase::SetFlags,
*/
This function writes a buffer of @a nbytes bytes to the socket.
Use wxSocketBase::LastCount to verify the number of bytes actually wrote.
Use wxSocketBase::Error to determine if the operation succeeded.
-
+
@param address
The address of the destination peer for this data.
@param buffer
Buffer where read data is.
@param nbytes
Number of bytes.
-
+
@returns Returns a reference to the current object.
*/
wxDatagramSocket SendTo(const wxSockAddress& address,
const void* buffer,
wxUint32 nbytes);
};
+