Version: 3.1.0
wxProtocol Class Referenceabstract

#include <wx/protocol/protocol.h>

+ Inheritance diagram for wxProtocol:

Detailed Description

Represents a protocol for use with wxURL.

Note that you may want to change the default time-out for HTTP/FTP connections and network operations (using SetDefaultTimeout()) since the default time-out value is quite long (60 seconds).

Library:  wxNet
Category:  Networking
See Also
wxSocketBase, wxURL

Public Member Functions

virtual bool Abort ()=0
 Abort the current stream.
 
virtual wxString GetContentType () const
 Returns the type of the content of the last opened stream.
 
virtual wxProtocolError GetError () const
 Returns the last occurred error.
 
virtual wxInputStreamGetInputStream (const wxString &path)=0
 Creates a new input stream on the specified path.
 
bool Reconnect ()
 Tries to reestablish a previous opened connection (close and renegotiate connection).
 
virtual void SetPassword (const wxString &user)
 Sets the authentication password.
 
virtual void SetUser (const wxString &user)
 Sets the authentication user.
 
void SetDefaultTimeout (wxUint32 Value)
 Sets a new default timeout for the network operations.
 
Logging support.

Each wxProtocol object may have the associated logger (by default there is none) which is used to log network requests and responses.

See Also
wxProtocolLog
void SetLog (wxProtocolLog *log)
 Set the logger, deleting the old one and taking ownership of this one.
 
wxProtocolLogGetLog () const
 Return the current logger, may be NULL.
 
wxProtocolLogDetachLog ()
 Detach the existing logger without deleting it.
 
void LogRequest (const wxString &str)
 Call wxProtocolLog::LogRequest() if we have a valid logger or do nothing otherwise.
 
void LogResponse (const wxString &str)
 Call wxProtocolLog::LogResponse() if we have a valid logger or do nothing otherwise.
 
- Public Member Functions inherited from wxSocketClient
 wxSocketClient (wxSocketFlags flags=wxSOCKET_NONE)
 Constructor.
 
virtual ~wxSocketClient ()
 Destructor.
 
virtual bool Connect (const wxSockAddress &address, bool wait=true)
 Connects to a server using the specified address.
 
bool Connect (const wxSockAddress &address, const wxSockAddress &local, bool wait=true)
 Connects to a server using the specified address.
 
bool WaitOnConnect (long seconds=-1, long milliseconds=0)
 Wait until a connection request completes, or until the specified timeout elapses.
 
- Public Member Functions inherited from wxSocketBase
bool Error () const
 Returns true if an error occurred in the last IO operation.
 
virtual bool GetLocal (wxSockAddress &addr) const
 Return the local address of the socket.
 
virtual bool GetPeer (wxSockAddress &addr) const
 Return the peer address field of the socket.
 
long GetTimeout () const
 Return the socket timeout in seconds.
 
bool IsConnected () const
 Returns true if the socket is connected.
 
bool IsData ()
 Check if the socket can be currently read or written.
 
bool IsDisconnected () const
 Returns true if the socket is not connected.
 
bool IsOk () const
 Returns true if the socket is initialized and ready and false in other cases.
 
wxUint32 LastCount () const
 Returns the number of bytes read or written by the last IO call.
 
wxUint32 LastReadCount () const
 Returns the number of bytes read by the last Read() or ReadMsg() call (receive direction only).
 
wxUint32 LastWriteCount () const
 Returns the number of bytes written by the last Write() or WriteMsg() call (transmit direction only).
 
wxSocketError LastError () const
 Returns the last wxSocket error.
 
void RestoreState ()
 Restore the previous state of the socket, as saved with SaveState().
 
void SaveState ()
 Save the current state of the socket in a stack.
 
virtual bool Close ()
 Shut down the socket, disabling further transmission and reception of data and disable events for the socket and frees the associated system resources.
 
void ShutdownOutput ()
 Shuts down the writing end of the socket.
 
wxSocketBaseDiscard ()
 Delete all bytes in the incoming queue.
 
wxSocketFlags GetFlags () const
 Returns current IO flags, as set with SetFlags()
 
void InterruptWait ()
 Use this function to interrupt any wait operation currently in progress.
 
wxSocketBasePeek (void *buffer, wxUint32 nbytes)
 Peek into the socket by copying the next bytes which would be read by Read() into the provided buffer.
 
wxSocketBaseRead (void *buffer, wxUint32 nbytes)
 Read up to the given number of bytes from the socket.
 
wxSocketBaseReadMsg (void *buffer, wxUint32 nbytes)
 Receive a message sent by WriteMsg().
 
void SetFlags (wxSocketFlags flags)
 Use SetFlags to customize IO operation for this socket.
 
virtual bool SetLocal (const wxIPV4address &local)
 Set the local address and port to use.
 
void SetTimeout (long seconds)
 Set the default socket timeout in seconds.
 
wxSocketBaseUnread (const void *buffer, wxUint32 nbytes)
 Put the specified data into the input queue.
 
bool Wait (long seconds=-1, long millisecond=0)
 Wait for any socket event.
 
bool WaitForLost (long seconds=-1, long millisecond=0)
 Wait until the connection is lost.
 
bool WaitForRead (long seconds=-1, long millisecond=0)
 Wait until the socket is readable.
 
bool WaitForWrite (long seconds=-1, long millisecond=0)
 Wait until the socket becomes writable.
 
wxSocketBaseWrite (const void *buffer, wxUint32 nbytes)
 Write up to the given number of bytes to the socket.
 
wxSocketBaseWriteMsg (const void *buffer, wxUint32 nbytes)
 Sends a buffer which can be read using ReadMsg().
 
void * GetClientData () const
 Returns a pointer of the client data for this socket, as set with SetClientData()
 
void Notify (bool notify)
 According to the notify value, this function enables or disables socket events.
 
void SetClientData (void *data)
 Sets user-supplied client data for this socket.
 
void SetEventHandler (wxEvtHandler &handler, int id=-1)
 Sets an event handler to be called when a socket event occurs.
 
void SetNotify (wxSocketEventFlags flags)
 Specifies which socket events are to be sent to the event handler.
 
wxSOCKET_T GetSocket () const
 Returns the native socket descriptor.
 
 wxSocketBase ()
 Default constructor.
 
virtual ~wxSocketBase ()
 Destructor.
 
bool Destroy ()
 Destroys the socket safely.
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data.
 
 wxObject (const wxObject &other)
 Copy ctor.
 
virtual ~wxObject ()
 Destructor.
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 

Additional Inherited Members

- Static Public Member Functions inherited from wxSocketBase
static bool Initialize ()
 Perform the initialization needed in order to use the sockets.
 
static void Shutdown ()
 Shut down the sockets.
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object.
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data.
 

Member Function Documentation

virtual bool wxProtocol::Abort ( )
pure virtual

Abort the current stream.

Warning
It is advised to destroy the input stream instead of aborting the stream this way.
Returns
Returns true, if successful, else false.

Implemented in wxFTP.

wxProtocolLog* wxProtocol::DetachLog ( )

Detach the existing logger without deleting it.

The caller is responsible for deleting the returned pointer if it's non-NULL.

virtual wxString wxProtocol::GetContentType ( ) const
virtual

Returns the type of the content of the last opened stream.

It is a mime-type. May be an empty string if the content-type is unknown.

virtual wxProtocolError wxProtocol::GetError ( ) const
virtual

Returns the last occurred error.

See Also
wxProtocolError
virtual wxInputStream* wxProtocol::GetInputStream ( const wxString path)
pure virtual

Creates a new input stream on the specified path.

You can use all but seek() functionality of wxStream. Seek() isn't available on all streams. For example, HTTP or FTP streams don't deal with it. Other functions like StreamSize() and Tell() aren't available for the moment for this sort of stream. You will be notified when the EOF is reached by an error.

Returns
Returns the initialized stream. You will have to delete it yourself once you don't use it anymore. The destructor closes the network connection.
See Also
wxInputStream

Implemented in wxFTP, and wxHTTP.

wxProtocolLog* wxProtocol::GetLog ( ) const
inline

Return the current logger, may be NULL.

void wxProtocol::LogRequest ( const wxString str)

Call wxProtocolLog::LogRequest() if we have a valid logger or do nothing otherwise.

void wxProtocol::LogResponse ( const wxString str)

Call wxProtocolLog::LogResponse() if we have a valid logger or do nothing otherwise.

bool wxProtocol::Reconnect ( )

Tries to reestablish a previous opened connection (close and renegotiate connection).

Returns
true, if the connection is established, else false.
void wxProtocol::SetDefaultTimeout ( wxUint32  Value)

Sets a new default timeout for the network operations.

The default timeout is 60 seconds.

See Also
wxSocketBase::SetTimeout
void wxProtocol::SetLog ( wxProtocolLog log)

Set the logger, deleting the old one and taking ownership of this one.

Parameters
logNew logger allocated on the heap or NULL.
virtual void wxProtocol::SetPassword ( const wxString user)
virtual

Sets the authentication password.

Reimplemented in wxFTP.

virtual void wxProtocol::SetUser ( const wxString user)
virtual

Sets the authentication user.

Reimplemented in wxFTP.