2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: socket.h
|
2008-10-05 11:24:00 +00:00
|
|
|
// Purpose: interface of wxIP*address, wxSocket* classes
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-08 16:33:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxIPaddress
|
|
|
|
|
|
|
|
wxIPaddress is an abstract base class for all internet protocol address
|
|
|
|
objects. Currently, only wxIPV4address is implemented. An experimental
|
|
|
|
implementation for IPV6, wxIPV6address, is being developed.
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{net}
|
|
|
|
*/
|
|
|
|
class wxIPaddress : public wxSockAddress
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Internally, this is the same as setting the IP address to @b INADDR_ANY.
|
|
|
|
|
|
|
|
On IPV4 implementations, 0.0.0.0
|
|
|
|
|
|
|
|
On IPV6 implementations, ::
|
|
|
|
|
|
|
|
@return @true on success, @false if something went wrong.
|
|
|
|
*/
|
|
|
|
bool AnyAddress();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internally, this is the same as setting the IP address to @b INADDR_BROADCAST.
|
|
|
|
|
|
|
|
On IPV4 implementations, 255.255.255.255
|
|
|
|
|
|
|
|
@return @true on success, @false if something went wrong.
|
|
|
|
*/
|
|
|
|
virtual bool BroadcastAddress() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the address to hostname, which can be a host name or an IP-style address
|
|
|
|
in a format dependent on implementation.
|
|
|
|
|
|
|
|
@return @true on success, @false if something goes wrong (invalid
|
|
|
|
hostname or invalid IP address).
|
|
|
|
*/
|
|
|
|
bool Hostname(const wxString& hostname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the hostname which matches the IP address.
|
|
|
|
*/
|
|
|
|
wxString Hostname() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a wxString containing the IP address.
|
|
|
|
*/
|
|
|
|
virtual wxString IPAddress() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Determines if current address is set to localhost.
|
|
|
|
|
|
|
|
@return @true if address is localhost, @false if internet address.
|
|
|
|
*/
|
|
|
|
virtual bool IsLocalHost() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set address to localhost.
|
|
|
|
|
|
|
|
On IPV4 implementations, 127.0.0.1
|
|
|
|
|
|
|
|
On IPV6 implementations, ::1
|
|
|
|
|
|
|
|
@return @true on success, @false if something went wrong.
|
|
|
|
*/
|
|
|
|
bool LocalHost();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the port to that corresponding to the specified service.
|
|
|
|
|
|
|
|
@return @true on success, @false if something goes wrong (invalid @a service).
|
|
|
|
*/
|
|
|
|
bool Service(const wxString& service);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the port to that corresponding to the specified service.
|
|
|
|
|
|
|
|
@return @true on success, @false if something goes wrong (invalid @a service).
|
|
|
|
*/
|
|
|
|
bool Service(unsigned short service);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current service.
|
|
|
|
*/
|
|
|
|
unsigned short Service() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxIPV4address
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
A class for working with IPv4 network addresses.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{net}
|
|
|
|
*/
|
|
|
|
class wxIPV4address : public wxIPaddress
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Set address to any of the addresses of the current machine.
|
|
|
|
|
|
|
|
Whenever possible, use this function instead of LocalHost(),
|
2008-03-08 13:52:38 +00:00
|
|
|
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.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@return @true on success, @false if something went wrong.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool AnyAddress();
|
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Set the address to hostname, which can be a host name or an IP-style address
|
2008-10-05 11:24:00 +00:00
|
|
|
in dot notation(<tt>a.b.c.d</tt>).
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@return @true on success, @false if something goes wrong (invalid
|
|
|
|
hostname or invalid IP address).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool Hostname(const wxString& hostname);
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the hostname which matches the IP address.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString Hostname() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a wxString containing the IP address in dot quad (127.0.0.1) format.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString IPAddress() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Set address to localhost (127.0.0.1).
|
|
|
|
|
|
|
|
Whenever possible, use AnyAddress() instead of this one, as that one will
|
|
|
|
correctly handle multi-homed hosts and avoid other small problems.
|
|
|
|
|
|
|
|
@return @true on success, @false if something went wrong.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool LocalHost();
|
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Set the port to that corresponding to the specified @a service.
|
|
|
|
|
|
|
|
@return @true on success, @false if something goes wrong (invalid @a service).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool Service(const wxString& service);
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the port to that corresponding to the specified @a service.
|
|
|
|
|
|
|
|
@return @true on success, @false if something goes wrong (invalid @a service).
|
|
|
|
*/
|
2009-01-08 16:33:08 +00:00
|
|
|
bool Service(unsigned short service);
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current service.
|
|
|
|
*/
|
2009-01-08 16:33:08 +00:00
|
|
|
unsigned short Service() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxSocketServer
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@todo describe me.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxnet}
|
|
|
|
@category{net}
|
|
|
|
*/
|
|
|
|
class wxSocketServer : public wxSocketBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructs a new server and tries to bind to the specified @e address.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
Before trying to accept new connections, remember to test whether it succeeded
|
|
|
|
with wxSocketBase:IsOk().
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param address
|
2008-03-09 12:33:59 +00:00
|
|
|
Specifies the local address for the server (e.g. port number).
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2008-10-05 11:24:00 +00:00
|
|
|
Socket flags (See wxSocketBase::SetFlags()).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxSocketServer(const wxSockAddress& address,
|
|
|
|
wxSocketFlags flags = wxSOCKET_NONE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor (it doesn't close the accepted connections).
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxSocketServer();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-05 11:24:00 +00:00
|
|
|
Accepts an incoming connection request, and creates a new wxSocketBase
|
|
|
|
object which represents the server-side of the connection.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
If @a wait is @true and there are no pending connections to be
|
2008-03-08 13:52:38 +00:00
|
|
|
accepted, it will wait for the next incoming connection to
|
2008-10-05 11:24:00 +00:00
|
|
|
arrive.
|
|
|
|
|
2009-01-14 15:03:55 +00:00
|
|
|
@warning This method will block the GUI.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
If @a wait is @false, it will try to accept a pending connection
|
2008-03-08 13:52:38 +00:00
|
|
|
if there is one, but it will always return immediately without blocking
|
2008-08-04 18:02:55 +00:00
|
|
|
the GUI. If you want to use Accept() in this way, you can either check for
|
|
|
|
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.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns an opened socket connection, or @NULL if an error
|
2008-08-04 18:02:55 +00:00
|
|
|
occurred or if the wait parameter was @false and there
|
|
|
|
were no pending connections.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@see WaitForAccept(), wxSocketBase::SetNotify(),
|
|
|
|
wxSocketBase::Notify(), AcceptWith()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxSocketBase* Accept(bool wait = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Accept an incoming connection using the specified socket object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param socket
|
2008-03-09 12:33:59 +00:00
|
|
|
Socket to be initialized
|
2008-10-05 11:24:00 +00:00
|
|
|
@param wait
|
|
|
|
See Accept() for more info.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@return Returns @true on success, or @false if an error occurred or
|
|
|
|
if the wait parameter was @false and there were no pending
|
|
|
|
connections.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@see WaitForAccept(), wxSocketBase::SetNotify(),
|
|
|
|
wxSocketBase::Notify(), Accept()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
bool AcceptWith(wxSocketBase& socket, bool wait = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Wait for an incoming connection.
|
2008-10-05 11:24:00 +00:00
|
|
|
|
|
|
|
Use it if you want to call Accept() or AcceptWith() with @e wait set
|
|
|
|
to @false, to detect when an incoming connection is waiting to be accepted.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-08-04 18:02:55 +00:00
|
|
|
Number of seconds to wait. If -1, it will wait for the default
|
|
|
|
timeout, as set with wxSocketBase::SetTimeout().
|
2008-03-08 14:43:31 +00:00
|
|
|
@param millisecond
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@return @true if an incoming connection arrived, @false if the timeout
|
|
|
|
elapsed.
|
|
|
|
|
|
|
|
@see Accept(), AcceptWith(), wxSocketBase::InterruptWait()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool WaitForAccept(long seconds = -1, long millisecond = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxSocketClient
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@todo describe me.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxnet}
|
|
|
|
@category{net}
|
|
|
|
*/
|
|
|
|
class wxSocketClient : public wxSocketBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2008-08-04 18:02:55 +00:00
|
|
|
Socket flags (See wxSocketBase::SetFlags())
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxSocketClient(wxSocketFlags flags = wxSOCKET_NONE);
|
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Destructor. Please see wxSocketBase::Destroy().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxSocketClient();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Connects to a server using the specified address.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
If @a wait is @true, Connect() will wait until the connection
|
2008-10-05 11:24:00 +00:00
|
|
|
completes.
|
|
|
|
|
2009-01-14 15:03:55 +00:00
|
|
|
@warning This method will block the GUI.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
If @a wait is @false, Connect() will try to establish the connection
|
|
|
|
and return immediately, without blocking the GUI. When used this way,
|
|
|
|
even if Connect() returns @false, the connection request can be
|
|
|
|
completed later. 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 wait
|
|
|
|
If @true, waits for the connection to complete.
|
|
|
|
|
|
|
|
@return @true if the connection is established and no error occurs.
|
2008-10-05 11:24:00 +00:00
|
|
|
If @a wait was true, and Connect() returns @false, an error
|
|
|
|
occurred and the connection failed.
|
|
|
|
If @a wait was @false, and Connect() returns @false, you should
|
|
|
|
still be prepared to handle the completion of this connection request,
|
|
|
|
either with WaitOnConnect() or by watching wxSOCKET_CONNECTION
|
|
|
|
and wxSOCKET_LOST events.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@see WaitOnConnect(), wxSocketBase::SetNotify(), wxSocketBase::Notify()
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual bool Connect(const wxSockAddress& address, bool wait = true);
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Connects to a server using the specified address.
|
|
|
|
|
|
|
|
If @a wait is @true, Connect() will wait until the connection
|
|
|
|
completes. @b Warning: This will block the GUI.
|
|
|
|
|
|
|
|
If @a wait is @false, Connect() will try to establish the connection
|
|
|
|
and return immediately, without blocking the GUI. When used this way,
|
|
|
|
even if Connect() returns @false, the connection request can be
|
|
|
|
completed later. To detect this, use WaitOnConnect(), or catch
|
|
|
|
@b wxSOCKET_CONNECTION events (for successful establishment) and
|
|
|
|
@b wxSOCKET_LOST events (for connection failure).
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param address
|
2008-03-09 12:33:59 +00:00
|
|
|
Address of the server.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param local
|
2008-03-09 12:33:59 +00:00
|
|
|
Bind to the specified local address and port before connecting.
|
2008-08-04 18:02:55 +00:00
|
|
|
The local address and port can also be set using SetLocal(),
|
|
|
|
and then using the 2-parameter Connect() method.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param wait
|
2008-03-09 12:33:59 +00:00
|
|
|
If @true, waits for the connection to complete.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@return @true if the connection is established and no error occurs.
|
2008-10-05 11:24:00 +00:00
|
|
|
If @a wait was true, and Connect() returns @false, an error
|
|
|
|
occurred and the connection failed.
|
|
|
|
If @a wait was @false, and Connect() returns @false, you should
|
|
|
|
still be prepared to handle the completion of this connection request,
|
|
|
|
either with WaitOnConnect() or by watching wxSOCKET_CONNECTION
|
|
|
|
and wxSOCKET_LOST events.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@see WaitOnConnect(), wxSocketBase::SetNotify(), wxSocketBase::Notify()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-07-06 02:21:39 +00:00
|
|
|
bool Connect(const wxSockAddress& address, const wxSockAddress& local,
|
2008-03-09 12:33:59 +00:00
|
|
|
bool wait = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Wait until a connection request completes, or until the specified timeout
|
2008-10-05 11:24:00 +00:00
|
|
|
elapses. Use this function after issuing a call to Connect() with
|
|
|
|
@e wait set to @false.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of seconds to wait.
|
2008-10-05 11:24:00 +00:00
|
|
|
If -1, it will wait for the default timeout, as set with wxSocketBase::SetTimeout().
|
|
|
|
@param milliseconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@return
|
|
|
|
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
|
|
|
|
connection was refused by the peer. Use wxSocketBase::IsConnected()
|
|
|
|
to distinguish between these two situations.
|
|
|
|
@n @n If the timeout elapses, WaitOnConnect() returns @false.
|
|
|
|
@n @n These semantics allow code like this:
|
|
|
|
@code
|
|
|
|
// Issue the connection request
|
|
|
|
client->Connect(addr, false);
|
|
|
|
|
|
|
|
// Wait until the request completes or until we decide to give up
|
|
|
|
bool waitmore = true;
|
|
|
|
while ( !client->WaitOnConnect(seconds, millis) && waitmore )
|
|
|
|
{
|
|
|
|
// possibly give some feedback to the user,
|
|
|
|
// and update waitmore as needed.
|
|
|
|
}
|
|
|
|
bool success = client->IsConnected();
|
|
|
|
@endcode
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool WaitOnConnect(long seconds = -1, long milliseconds = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxSockAddress
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
You are unlikely to need to use this class: only wxSocketBase uses it.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-08-04 18:02:55 +00:00
|
|
|
@category{net}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxSocketBase, wxIPaddress, wxIPV4address
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxSockAddress : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxSockAddress();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Default destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxSockAddress();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Delete all informations about the address.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void Clear();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the socket address.
|
|
|
|
*/
|
|
|
|
int SockAddrLen();
|
2009-02-22 23:38:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the pointer to the low-level representation of the address.
|
|
|
|
|
|
|
|
This can be used to pass socket address information to a 3rd party
|
|
|
|
library.
|
|
|
|
|
|
|
|
@return
|
|
|
|
Pointer to a sockaddr-derived struct.
|
|
|
|
*/
|
|
|
|
const sockaddr *GetAddressData() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the buffer retrieved by GetAddressData().
|
|
|
|
|
|
|
|
@return
|
|
|
|
The size of the sockaddr-derived struct corresponding to this
|
|
|
|
address.
|
|
|
|
*/
|
|
|
|
int GetAddressDataLen() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxSocketEvent
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
This event class contains information about socket events.
|
2009-02-18 17:58:51 +00:00
|
|
|
This kind of events are sent to the event handler specified with
|
|
|
|
wxSocketBase::SetEventHandler.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@beginEventTable{wxSocketEvent}
|
|
|
|
@event{EVT_SOCKET(id, func)}
|
2009-02-18 17:58:51 +00:00
|
|
|
Process a socket event, supplying the member function.
|
2008-08-04 18:02:55 +00:00
|
|
|
@endEventTable
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxnet}
|
|
|
|
@category{net}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxSocketBase, wxSocketClient, wxSocketServer
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxSocketEvent : public wxEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxSocketEvent(int id = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the client data of the socket which generated this event, as
|
2008-08-04 18:02:55 +00:00
|
|
|
set with wxSocketBase::SetClientData().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
void* GetClientData() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-05 11:24:00 +00:00
|
|
|
Returns the socket object to which this event refers to.
|
|
|
|
This makes it possible to use the same event handler for different sockets.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxSocketBase* GetSocket() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the socket event type.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxSocketNotify GetSocketEvent() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
/**
|
|
|
|
wxSocket error return values.
|
|
|
|
*/
|
|
|
|
enum wxSocketError
|
|
|
|
{
|
|
|
|
wxSOCKET_NOERROR, ///< No error happened.
|
|
|
|
wxSOCKET_INVOP, ///< Invalid operation.
|
|
|
|
wxSOCKET_IOERR, ///< Input/Output error.
|
|
|
|
wxSOCKET_INVADDR, ///< Invalid address passed to wxSocket.
|
|
|
|
wxSOCKET_INVSOCK, ///< Invalid socket (uninitialized).
|
|
|
|
wxSOCKET_NOHOST, ///< No corresponding host.
|
|
|
|
wxSOCKET_INVPORT, ///< Invalid port.
|
|
|
|
wxSOCKET_WOULDBLOCK, ///< The socket is non-blocking and the operation would block.
|
|
|
|
wxSOCKET_TIMEDOUT, ///< The timeout for this operation expired.
|
|
|
|
wxSOCKET_MEMERR ///< Memory exhausted.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-05 11:24:00 +00:00
|
|
|
@anchor wxSocketEventFlags
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
wxSocket Event Flags.
|
|
|
|
|
|
|
|
A brief note on how to use these events:
|
|
|
|
|
|
|
|
The @b wxSOCKET_INPUT event will be issued whenever there is data available
|
|
|
|
for reading. This will be the case if the input queue was empty and new data
|
|
|
|
arrives, or if the application has read some data yet there is still more data
|
|
|
|
available. This means that the application does not need to read all available
|
|
|
|
data in response to a @b wxSOCKET_INPUT event, as more events will be produced
|
|
|
|
as necessary.
|
|
|
|
|
|
|
|
The @b wxSOCKET_OUTPUT event is issued when a socket is first connected with
|
|
|
|
Connect() or accepted with Accept(). After that, new events will be generated
|
|
|
|
only after an output operation fails with @b wxSOCKET_WOULDBLOCK and buffer space
|
|
|
|
becomes available again. This means that the application should assume that it can
|
|
|
|
write data to the socket until an @b wxSOCKET_WOULDBLOCK error occurs; after this,
|
|
|
|
whenever the socket becomes writable again the application will be notified with
|
|
|
|
another @b wxSOCKET_OUTPUT event.
|
|
|
|
|
|
|
|
The @b wxSOCKET_CONNECTION event is issued when a delayed connection request completes
|
|
|
|
successfully (client) or when a new connection arrives at the incoming queue (server).
|
|
|
|
|
|
|
|
The @b wxSOCKET_LOST event is issued when a close indication is received for the socket.
|
|
|
|
This means that the connection broke down or that it was closed by the peer. Also, this
|
|
|
|
event will be issued if a connection request fails.
|
|
|
|
*/
|
|
|
|
enum wxSocketEventFlags
|
|
|
|
{
|
|
|
|
wxSOCKET_INPUT, ///< There is data available for reading.
|
|
|
|
wxSOCKET_OUTPUT, ///< The socket is ready to be written to.
|
|
|
|
wxSOCKET_CONNECTION, ///< Incoming connection request (server), or
|
|
|
|
///< successful connection establishment (client).
|
|
|
|
wxSOCKET_LOST ///< The connection has been closed.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@anchor wxSocketFlags
|
|
|
|
|
|
|
|
wxSocket Flags.
|
|
|
|
|
|
|
|
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
|
|
|
|
when the transfer might not be complete. This is the same as issuing
|
|
|
|
exactly one blocking low-level call to @b recv() or @b send(). Note
|
|
|
|
that @e blocking here refers to when the function returns, not
|
|
|
|
to whether the GUI blocks during this time.
|
|
|
|
|
|
|
|
If @b wxSOCKET_NOWAIT is specified, IO calls will return immediately.
|
|
|
|
Read operations will retrieve only available data. Write operations will
|
|
|
|
write as much data as possible, depending on how much space is available
|
|
|
|
in the output buffer. This is the same as issuing exactly one nonblocking
|
|
|
|
low-level call to @b recv() or @b send(). Note that @e nonblocking here
|
|
|
|
refers to when the function returns, not to whether the GUI blocks during
|
|
|
|
this time.
|
|
|
|
|
|
|
|
If @b wxSOCKET_WAITALL is specified, IO calls won't return until ALL
|
|
|
|
the data has been read or written (or until an error occurs), blocking if
|
|
|
|
necessary, and issuing several low level calls if necessary. This is the
|
|
|
|
same as having a loop which makes as many blocking low-level calls to
|
|
|
|
@b recv() or @b send() as needed so as to transfer all the data. Note
|
|
|
|
that @e blocking here refers to when the function returns, not
|
|
|
|
to whether the GUI blocks during this time.
|
|
|
|
|
|
|
|
The @b wxSOCKET_BLOCK flag controls whether the GUI blocks during
|
|
|
|
IO operations. If this flag is specified, the socket will not yield
|
|
|
|
during IO calls, so the GUI will remain blocked until the operation
|
|
|
|
completes. If it is not used, then the application must take extra
|
|
|
|
care to avoid unwanted reentrance.
|
|
|
|
|
|
|
|
The @b wxSOCKET_REUSEADDR flag controls the use of the @b SO_REUSEADDR standard
|
|
|
|
@b setsockopt() flag. This flag allows the socket to bind to a port that is
|
|
|
|
already in use. This is mostly used on UNIX-based systems to allow rapid starting
|
|
|
|
and stopping of a server, otherwise you may have to wait several minutes for the
|
|
|
|
port to become available.
|
|
|
|
|
|
|
|
@b wxSOCKET_REUSEADDR can also be used with socket clients to (re)bind to a
|
|
|
|
particular local port for an outgoing connection.
|
2011-03-22 14:17:38 +00:00
|
|
|
This option can have surprising platform dependent behaviour, so check the
|
2008-08-04 18:02:55 +00:00
|
|
|
documentation for your platform's implementation of setsockopt().
|
|
|
|
|
|
|
|
Note that on BSD-based systems(e.g. Mac OS X), use of
|
|
|
|
@b wxSOCKET_REUSEADDR implies @b SO_REUSEPORT in addition to
|
|
|
|
@b SO_REUSEADDR to be consistent with Windows.
|
|
|
|
|
|
|
|
The @b wxSOCKET_BROADCAST flag controls the use of the @b SO_BROADCAST standard
|
|
|
|
@b setsockopt() flag. This flag allows the socket to use the broadcast address,
|
|
|
|
and is generally used in conjunction with @b wxSOCKET_NOBIND and
|
|
|
|
wxIPaddress::BroadcastAddress().
|
|
|
|
|
|
|
|
So:
|
2008-10-05 11:24:00 +00:00
|
|
|
- @b wxSOCKET_NONE will try to read at least SOME data, no matter how much.
|
|
|
|
- @b wxSOCKET_NOWAIT will always return immediately, even if it cannot
|
|
|
|
read or write ANY data.
|
|
|
|
- @b wxSOCKET_WAITALL will only return when it has read or written ALL
|
|
|
|
the data.
|
|
|
|
- @b wxSOCKET_BLOCK has nothing to do with the previous flags and
|
|
|
|
it controls whether the GUI blocks.
|
2011-03-22 14:17:38 +00:00
|
|
|
- @b wxSOCKET_REUSEADDR controls special platform-specific behaviour for
|
2008-10-05 11:24:00 +00:00
|
|
|
reusing local addresses/ports.
|
2008-08-04 18:02:55 +00:00
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxSOCKET_NONE = 0, ///< Normal functionality.
|
|
|
|
wxSOCKET_NOWAIT = 1, ///< Read/write as much data as possible and return immediately.
|
|
|
|
wxSOCKET_WAITALL = 2, ///< Wait for all required data to be read/written unless an error occurs.
|
|
|
|
wxSOCKET_BLOCK = 4, ///< Block the GUI (do not yield) while reading/writing data.
|
2009-03-22 22:02:30 +00:00
|
|
|
wxSOCKET_REUSEADDR = 8, ///< Allows the use of an in-use port.
|
2008-08-04 18:02:55 +00:00
|
|
|
wxSOCKET_BROADCAST = 16, ///< Switches the socket to broadcast mode
|
|
|
|
wxSOCKET_NOBIND = 32 ///< Stops the socket from being bound to a specific
|
|
|
|
///< adapter (normally used in conjunction with
|
|
|
|
///< @b wxSOCKET_BROADCAST)
|
|
|
|
};
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxSocketBase
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxSocketBase is the base class for all socket-related objects, and it
|
|
|
|
defines all basic IO functionality.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@note
|
2008-12-30 11:45:07 +00:00
|
|
|
When using wxSocket from multiple threads, even implicitly (e.g. by using
|
|
|
|
wxFTP or wxHTTP in another thread) you must initialize the sockets from the
|
|
|
|
main thread by calling Initialize() before creating the other ones.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-02-18 17:58:51 +00:00
|
|
|
@beginEventEmissionTable{wxSocketEvent}
|
2008-08-04 18:02:55 +00:00
|
|
|
@event{EVT_SOCKET(id, func)}
|
|
|
|
Process a @c wxEVT_SOCKET event.
|
2008-10-05 11:24:00 +00:00
|
|
|
See @ref wxSocketEventFlags and @ref wxSocketFlags for more info.
|
2008-08-04 18:02:55 +00:00
|
|
|
@endEventTable
|
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
@library{wxnet}
|
|
|
|
@category{net}
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@see wxSocketEvent, wxSocketClient, wxSocketServer, @sample{sockets},
|
|
|
|
@ref wxSocketFlags, ::wxSocketEventFlags, ::wxSocketError
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxSocketBase : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
@name Construction and Destruction
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-08-04 18:02:55 +00:00
|
|
|
//@{
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Default constructor.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
Don't use it directly; instead, use wxSocketClient to construct a socket client,
|
|
|
|
or wxSocketServer to construct a socket server.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-08-04 18:02:55 +00:00
|
|
|
wxSocketBase();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Destructor.
|
|
|
|
|
|
|
|
Do not destroy a socket using the delete operator directly;
|
|
|
|
use Destroy() instead. Also, do not create socket objects in the stack.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
virtual ~wxSocketBase();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Destroys the socket safely.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
Use this function instead of the delete operator, since otherwise socket events
|
|
|
|
could reach the application even after the socket has been destroyed. To prevent
|
|
|
|
this problem, this function appends the wxSocket to a list of object to be deleted
|
|
|
|
on idle time, after all events have been processed. For the same reason, you should
|
|
|
|
avoid creating socket objects in the stack.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
Destroy() calls Close() automatically.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Always @true.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool Destroy();
|
|
|
|
|
2008-12-30 11:45:07 +00:00
|
|
|
/**
|
|
|
|
Perform the initialization needed in order to use the sockets.
|
|
|
|
|
|
|
|
This function is called from wxSocket constructor implicitly and so
|
|
|
|
normally doesn't need to be called explicitly. There is however one
|
|
|
|
important exception: as this function must be called from the main
|
|
|
|
(UI) thread, if you use wxSocket from multiple threads you must call
|
|
|
|
Initialize() from the main thread before creating wxSocket objects in
|
|
|
|
the other ones.
|
|
|
|
|
|
|
|
It is safe to call this function multiple times (only the first call
|
|
|
|
does anything) but you must call Shutdown() exactly once for every call
|
|
|
|
to Initialize().
|
|
|
|
|
2009-09-21 08:44:35 +00:00
|
|
|
This function should only be called from the main thread.
|
|
|
|
|
2008-12-30 11:45:07 +00:00
|
|
|
@return
|
|
|
|
@true if the sockets can be used, @false if the initialization
|
|
|
|
failed and sockets are not available at all.
|
|
|
|
*/
|
|
|
|
static bool Initialize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Shut down the sockets.
|
|
|
|
|
|
|
|
This function undoes the call to Initialize() and must be called after
|
|
|
|
every successful call to Initialize().
|
2009-09-21 08:44:35 +00:00
|
|
|
|
|
|
|
This function should only be called from the main thread, just as
|
|
|
|
Initialize().
|
2008-12-30 11:45:07 +00:00
|
|
|
*/
|
|
|
|
static void Shutdown();
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
@name Socket State
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-08-04 18:02:55 +00:00
|
|
|
//@{
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if an error occurred in the last IO operation.
|
2008-07-12 02:28:12 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
Use this function to check for an error condition after one of the
|
|
|
|
following calls: Discard(), Peek(), Read(), ReadMsg(), Unread(), Write(), WriteMsg().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool Error() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Return the local address of the socket.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true if no error happened, @false otherwise.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
virtual bool GetLocal(wxSockAddress& addr) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Return the peer address field of the socket.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true if no error happened, @false otherwise.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
virtual bool GetPeer(wxSockAddress& addr) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-11-23 13:11:25 +00:00
|
|
|
/**
|
|
|
|
Return the socket timeout in seconds.
|
|
|
|
|
|
|
|
The timeout can be set using SetTimeout() and is 10 minutes by default.
|
|
|
|
*/
|
|
|
|
long GetTimeout() const;
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Returns @true if the socket is connected.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsConnected() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-07-12 02:28:12 +00:00
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Check if the socket can be currently read or written.
|
2008-07-12 02:28:12 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
This might mean that queued data is available for reading or, for streamed
|
|
|
|
sockets, that the connection has been closed, so that a read operation will
|
|
|
|
complete immediately without blocking (unless the @b wxSOCKET_WAITALL flag
|
2008-03-08 13:52:38 +00:00
|
|
|
is set, in which case the operation might still block).
|
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
bool IsData();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the socket is not connected.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsDisconnected() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the socket is initialized and ready and @false in other
|
|
|
|
cases.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@remarks
|
|
|
|
For wxSocketClient, IsOk() won't return @true unless the client is connected to a server.
|
|
|
|
For wxSocketServer, IsOk() will return @true if the server could bind to the specified address
|
|
|
|
and is already listening for new connections.
|
|
|
|
IsOk() does not check for IO errors; use Error() instead for that purpose.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of bytes read or written by the last IO call.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use this function to get the number of bytes actually transferred
|
2008-08-04 18:02:55 +00:00
|
|
|
after using one of the following IO calls: Discard(), Peek(), Read(),
|
|
|
|
ReadMsg(), Unread(), Write(), WriteMsg().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxUint32 LastCount() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Returns the last wxSocket error. See @ref wxSocketError .
|
|
|
|
|
|
|
|
@note
|
|
|
|
This function merely returns the last error code,
|
2008-03-08 13:52:38 +00:00
|
|
|
but it should not be used to determine if an error has occurred (this
|
|
|
|
is because successful operations do not change the LastError value).
|
2008-08-04 18:02:55 +00:00
|
|
|
Use Error() first, in order to determine if the last IO call failed.
|
|
|
|
If this returns @true, use LastError() to discover the cause of the error.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxSocketError LastError() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Restore the previous state of the socket, as saved with SaveState().
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
Calls to SaveState() and RestoreState() can be nested.
|
|
|
|
|
|
|
|
@see SaveState()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-08-04 18:02:55 +00:00
|
|
|
void RestoreState();
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Save the current state of the socket in a stack.
|
|
|
|
|
2008-10-05 11:24:00 +00:00
|
|
|
Socket state includes flags, as set with SetFlags(), event mask, as set
|
|
|
|
with SetNotify() and Notify(), user data, as set with SetClientData().
|
2008-08-04 18:02:55 +00:00
|
|
|
Calls to SaveState and RestoreState can be nested.
|
|
|
|
|
|
|
|
@see RestoreState()
|
|
|
|
*/
|
|
|
|
void SaveState();
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@name Basic I/O
|
|
|
|
|
|
|
|
See also: wxSocketServer::WaitForAccept(), wxSocketClient::WaitOnConnect()
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Shut down the socket, disabling further transmission and reception of
|
|
|
|
data and disable events for the socket and frees the associated system
|
|
|
|
resources.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
Upon socket destruction, Close() is automatically called, so in most cases
|
|
|
|
you won't need to do it yourself, unless you explicitly want to shut down
|
|
|
|
the socket, typically to notify the peer that you are closing the connection.
|
|
|
|
|
|
|
|
@remarks
|
|
|
|
Although Close() immediately disables events for the socket, it is possible
|
|
|
|
that event messages may be waiting in the application's event queue.
|
|
|
|
The application must therefore be prepared to handle socket event messages even
|
|
|
|
after calling Close().
|
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
virtual bool Close();
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-12-30 11:27:41 +00:00
|
|
|
/**
|
|
|
|
Shuts down the writing end of the socket.
|
|
|
|
|
|
|
|
This function simply calls the standard shutdown() function on the
|
|
|
|
underlying socket, indicating that nothing will be written to this
|
|
|
|
socket any more.
|
|
|
|
*/
|
|
|
|
void ShutdownOutput();
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Delete all bytes in the incoming queue.
|
|
|
|
|
|
|
|
This function always returns immediately and its operation is not
|
|
|
|
affected by IO flags.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
Use LastCount() to verify the number of bytes actually discarded.
|
|
|
|
|
|
|
|
If you use Error(), it will always return @false.
|
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& Discard();
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns current IO flags, as set with SetFlags()
|
|
|
|
*/
|
|
|
|
wxSocketFlags GetFlags() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Use this function to interrupt any wait operation currently in progress.
|
|
|
|
|
|
|
|
Note that this is not intended as a regular way to interrupt a Wait call,
|
|
|
|
but only as an escape mechanism for exceptional situations where it is
|
|
|
|
absolutely necessary to use it, for example to abort an operation due to
|
|
|
|
some exception or abnormal problem. InterruptWait is automatically called
|
|
|
|
when you Close() a socket (and thus also upon
|
|
|
|
socket destruction), so you don't need to use it in these cases.
|
|
|
|
|
|
|
|
@see Wait(), WaitForLost(), WaitForRead(), WaitForWrite(),
|
2008-10-05 11:24:00 +00:00
|
|
|
wxSocketServer::WaitForAccept(), wxSocketClient::WaitOnConnect()
|
2008-08-04 18:02:55 +00:00
|
|
|
*/
|
|
|
|
void InterruptWait();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Peek into the socket by copying the next bytes which would be read by
|
|
|
|
Read() into the provided buffer.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
Peeking a buffer doesn't delete it from the socket input queue, i.e.
|
|
|
|
calling Read() will return the same data.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use LastCount() to verify the number of bytes actually peeked.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer where to put peeked data.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@remarks
|
2008-10-05 11:24:00 +00:00
|
|
|
The exact behaviour of Peek() depends on the combination of flags being used.
|
|
|
|
For a detailed explanation, see SetFlags()
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@see Error(), LastError(), LastCount(), SetFlags()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& Peek(void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Read up to the given number of bytes from the socket.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use LastCount() to verify the number of bytes actually read.
|
|
|
|
Use Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer where to put read data.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@remarks
|
2008-10-05 11:24:00 +00:00
|
|
|
The exact behaviour of Read() depends on the combination of flags being used.
|
|
|
|
For a detailed explanation, see SetFlags()
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Error(), LastError(), LastCount(),
|
|
|
|
SetFlags()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& Read(void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Receive a message sent by WriteMsg().
|
|
|
|
|
|
|
|
If the buffer passed to the function isn't big enough, the remaining
|
|
|
|
bytes will be discarded. This function always waits for the buffer to
|
|
|
|
be entirely filled, unless an error occurs.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use LastCount() to verify the number of bytes actually read.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer where to put read data.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Size of the buffer.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@remarks
|
2008-10-05 11:24:00 +00:00
|
|
|
ReadMsg() will behave as if the @b wxSOCKET_WAITALL flag was always set
|
|
|
|
and it will always ignore the @b wxSOCKET_NOWAIT flag.
|
|
|
|
The exact behaviour of ReadMsg() depends on the @b wxSOCKET_BLOCK flag.
|
|
|
|
For a detailed explanation, see SetFlags().
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@see Error(), LastError(), LastCount(), SetFlags(), WriteMsg()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& ReadMsg(void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Use SetFlags to customize IO operation for this socket.
|
2008-12-30 14:36:07 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
The @a flags parameter may be a combination of flags ORed together.
|
2008-12-30 14:36:07 +00:00
|
|
|
Notice that not all combinations of flags affecting the IO calls
|
|
|
|
(Read() and Write()) make sense, e.g. @b wxSOCKET_NOWAIT can't be
|
|
|
|
combined with @b wxSOCKET_WAITALL nor with @b wxSOCKET_BLOCK.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-12-30 14:36:07 +00:00
|
|
|
The following flags can be used:
|
2008-08-04 18:02:55 +00:00
|
|
|
@beginFlagTable
|
|
|
|
@flag{wxSOCKET_NONE}
|
2008-12-30 14:36:07 +00:00
|
|
|
Default mode: the socket will read some data in the IO calls and
|
|
|
|
will process events to avoid blocking UI while waiting for the data
|
|
|
|
to become available.
|
2008-08-04 18:02:55 +00:00
|
|
|
@flag{wxSOCKET_NOWAIT}
|
2008-12-30 14:36:07 +00:00
|
|
|
Don't wait for the socket to become ready in IO calls, read as much
|
|
|
|
data as is available -- potentially 0 bytes -- and return
|
|
|
|
immediately.
|
2008-08-04 18:02:55 +00:00
|
|
|
@flag{wxSOCKET_WAITALL}
|
2008-12-30 14:36:07 +00:00
|
|
|
Don't return before the entire amount of data specified in IO calls
|
|
|
|
is read or written unless an error occurs. If this flag is not
|
|
|
|
specified, the IO calls return as soon as any amount of data, even
|
|
|
|
less than the total number of bytes, is processed.
|
2008-08-04 18:02:55 +00:00
|
|
|
@flag{wxSOCKET_BLOCK}
|
2008-12-30 14:36:07 +00:00
|
|
|
Don't process the UI events while waiting for the socket to become
|
|
|
|
ready. This means that UI will be unresponsive during socket IO.
|
2008-08-04 18:02:55 +00:00
|
|
|
@flag{wxSOCKET_REUSEADDR}
|
|
|
|
Allows the use of an in-use port (wxServerSocket only).
|
|
|
|
@flag{wxSOCKET_BROADCAST}
|
|
|
|
Switches the socket to broadcast mode.
|
|
|
|
@flag{wxSOCKET_NOBIND}
|
|
|
|
Stops the socket from being bound to a specific adapter (normally
|
|
|
|
used in conjunction with @b wxSOCKET_BROADCAST).
|
|
|
|
@endFlagTable
|
|
|
|
|
|
|
|
For more information on socket events see @ref wxSocketFlags .
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetFlags(wxSocketFlags flags);
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Set the local address and port to use.
|
|
|
|
|
|
|
|
This function must always be called for the server sockets but may also
|
|
|
|
be called for client sockets, if it is, @b bind() is called before @b
|
|
|
|
connect().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
virtual bool SetLocal(const wxIPV4address& local);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Set the default socket timeout in seconds.
|
|
|
|
|
|
|
|
This timeout applies to all IO calls, and also to the Wait() family of
|
|
|
|
functions if you don't specify a wait interval. Initially, the default
|
2008-03-08 13:52:38 +00:00
|
|
|
timeout is 10 minutes.
|
|
|
|
*/
|
2009-01-10 22:42:09 +00:00
|
|
|
void SetTimeout(long seconds);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Put the specified data into the input queue.
|
|
|
|
|
|
|
|
The data in the buffer will be returned by the next call to Read().
|
|
|
|
|
|
|
|
This function is not affected by wxSocket flags.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
If you use LastCount(), it will always return @a nbytes.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
If you use Error(), it will always return @false.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer to be unread.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Error(), LastCount(), LastError()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& Unread(const void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Wait for any socket event.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
Possible socket events are:
|
2008-08-04 18:02:55 +00:00
|
|
|
@li The socket becomes readable.
|
|
|
|
@li The socket becomes writable.
|
|
|
|
@li An ongoing connection request has completed (wxSocketClient only)
|
|
|
|
@li An incoming connection request has arrived (wxSocketServer only)
|
|
|
|
@li The connection has been closed.
|
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
Note that it is recommended to use the individual @b WaitForXXX()
|
|
|
|
functions to wait for the required condition, instead of this one.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of seconds to wait.
|
|
|
|
If -1, it will wait for the default timeout,
|
2008-08-04 18:02:55 +00:00
|
|
|
as set with SetTimeout().
|
2008-03-08 14:43:31 +00:00
|
|
|
@param millisecond
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
@return
|
|
|
|
@true when any of the above conditions is satisfied or @false if the
|
|
|
|
timeout was reached.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@see InterruptWait(), wxSocketServer::WaitForAccept(),
|
2008-03-09 12:33:59 +00:00
|
|
|
WaitForLost(), WaitForRead(),
|
2008-08-04 18:02:55 +00:00
|
|
|
WaitForWrite(), wxSocketClient::WaitOnConnect()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool Wait(long seconds = -1, long millisecond = 0);
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Wait until the connection is lost.
|
|
|
|
|
|
|
|
This may happen if the peer gracefully closes the connection or if the
|
|
|
|
connection breaks.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of seconds to wait.
|
|
|
|
If -1, it will wait for the default timeout,
|
2008-08-04 18:02:55 +00:00
|
|
|
as set with SetTimeout().
|
2008-03-08 14:43:31 +00:00
|
|
|
@param millisecond
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns @true if the connection was lost, @false if the timeout
|
2008-10-05 11:24:00 +00:00
|
|
|
was reached.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see InterruptWait(), Wait()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-23 23:19:18 +00:00
|
|
|
bool WaitForLost(long seconds = -1, long millisecond = 0);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Wait until the socket is readable.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
This might mean that queued data is available for reading or, for streamed
|
|
|
|
sockets, that the connection has been closed, so that a read operation will
|
|
|
|
complete immediately without blocking (unless the @b wxSOCKET_WAITALL flag
|
2008-03-08 13:52:38 +00:00
|
|
|
is set, in which case the operation might still block).
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
Notice that this function should not be called if there is already data
|
|
|
|
available for reading on the socket.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of seconds to wait.
|
|
|
|
If -1, it will wait for the default timeout,
|
2008-08-04 18:02:55 +00:00
|
|
|
as set with SetTimeout().
|
2008-03-08 14:43:31 +00:00
|
|
|
@param millisecond
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns @true if the socket becomes readable, @false on timeout.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see InterruptWait(), Wait()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool WaitForRead(long seconds = -1, long millisecond = 0);
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Wait until the socket becomes writable.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
This might mean that the socket is ready to send new data, or for streamed
|
|
|
|
sockets, that the connection has been closed, so that a write operation is
|
|
|
|
guaranteed to complete immediately (unless the @b wxSOCKET_WAITALL flag is set,
|
2008-03-08 13:52:38 +00:00
|
|
|
in which case the operation might still block).
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
Notice that this function should not be called if the socket is already
|
|
|
|
writable.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param seconds
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of seconds to wait.
|
|
|
|
If -1, it will wait for the default timeout,
|
2008-08-04 18:02:55 +00:00
|
|
|
as set with SetTimeout().
|
2008-03-08 14:43:31 +00:00
|
|
|
@param millisecond
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of milliseconds to wait.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns @true if the socket becomes writable, @false on timeout.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see InterruptWait(), Wait()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
bool WaitForWrite(long seconds = -1, long millisecond = 0);
|
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Write up to the given number of bytes to the socket.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use LastCount() to verify the number of bytes actually written.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer with the data to be sent.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
@remarks
|
|
|
|
|
|
|
|
The exact behaviour of Write() depends on the combination of flags being used.
|
|
|
|
For a detailed explanation, see SetFlags().
|
|
|
|
|
|
|
|
@see Error(), LastError(), LastCount(), SetFlags()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& Write(const void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Sends a buffer which can be read using ReadMsg().
|
|
|
|
|
|
|
|
WriteMsg() sends a short header before the data so that ReadMsg()
|
|
|
|
knows how much data should be actually read.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-12-30 14:49:24 +00:00
|
|
|
This function always waits for the entire buffer to be sent, unless an
|
|
|
|
error occurs.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use LastCount() to verify the number of bytes actually written.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Use Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer with the data to be sent.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes to send.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@remarks
|
|
|
|
|
|
|
|
WriteMsg() will behave as if the @b wxSOCKET_WAITALL flag was always set and
|
|
|
|
it will always ignore the @b wxSOCKET_NOWAIT flag. The exact behaviour of
|
|
|
|
WriteMsg() depends on the @b wxSOCKET_BLOCK flag. For a detailed explanation,
|
|
|
|
see SetFlags().
|
|
|
|
|
|
|
|
@see Error(), LastError(), LastCount(), SetFlags(), ReadMsg()
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-12-30 14:49:24 +00:00
|
|
|
wxSocketBase& WriteMsg(const void* buffer, wxUint32 nbytes);
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@name Handling Socket Events
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer of the client data for this socket, as set with
|
|
|
|
SetClientData()
|
|
|
|
*/
|
|
|
|
void* GetClientData() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
According to the @a notify value, this function enables
|
|
|
|
or disables socket events. If @a notify is @true, the events
|
|
|
|
configured with SetNotify() will
|
|
|
|
be sent to the application. If @a notify is @false; no events
|
|
|
|
will be sent.
|
|
|
|
*/
|
|
|
|
void Notify(bool notify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets user-supplied client data for this socket. All socket events will
|
|
|
|
contain a pointer to this data, which can be retrieved with
|
|
|
|
the wxSocketEvent::GetClientData() function.
|
|
|
|
*/
|
|
|
|
void SetClientData(void* data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets an event handler to be called when a socket event occurs. The
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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:
|
|
|
|
|
|
|
|
@beginFlagTable
|
|
|
|
@flag{wxSOCKET_INPUT_FLAG} to receive @b wxSOCKET_INPUT.
|
|
|
|
@flag{wxSOCKET_OUTPUT_FLAG} to receive @b wxSOCKET_OUTPUT.
|
|
|
|
@flag{wxSOCKET_CONNECTION_FLAG} to receive @b wxSOCKET_CONNECTION.
|
|
|
|
@flag{wxSOCKET_LOST_FLAG} to receive @b wxSOCKET_LOST.
|
|
|
|
@endFlagTable
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
@code
|
|
|
|
sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
|
|
|
|
sock.Notify(true);
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
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 wxSocketEventFlags .
|
|
|
|
*/
|
|
|
|
void SetNotify(wxSocketEventFlags flags);
|
|
|
|
|
|
|
|
//@}
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDatagramSocket
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-19 16:07:00 +00:00
|
|
|
@todo docme
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxnet}
|
2008-08-04 18:02:55 +00:00
|
|
|
@category{net}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDatagramSocket : public wxSocketBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-10-19 16:07:00 +00:00
|
|
|
@param addr
|
|
|
|
The socket address.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2008-10-19 16:07:00 +00:00
|
|
|
Socket flags (See wxSocketBase::SetFlags()).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:46:42 +00:00
|
|
|
wxDatagramSocket(const wxSockAddress& addr,
|
|
|
|
wxSocketFlags flags = wxSOCKET_NONE);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-04 18:02:55 +00:00
|
|
|
Destructor. Please see wxSocketBase::Destroy().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxDatagramSocket();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-30 14:49:24 +00:00
|
|
|
Write a buffer of @a nbytes bytes to the socket.
|
|
|
|
|
2008-08-04 18:02:55 +00:00
|
|
|
Use wxSocketBase::LastCount() to verify the number of bytes actually wrote.
|
|
|
|
Use wxSocketBase::Error() to determine if the operation succeeded.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param address
|
2008-03-09 12:33:59 +00:00
|
|
|
The address of the destination peer for this data.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-03-09 12:33:59 +00:00
|
|
|
Buffer where read data is.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param nbytes
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of bytes.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns a reference to the current object.
|
2008-08-04 18:02:55 +00:00
|
|
|
|
|
|
|
@see wxSocketBase::LastError(), wxSocketBase::SetFlags()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-27 17:12:27 +00:00
|
|
|
wxDatagramSocket& SendTo(const wxSockAddress& address,
|
|
|
|
const void* buffer, wxUint32 nbytes);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|