\section{\class{wxDataInputStream}}\label{wxdatainputstream}
This class provides functions that read data types in a
-portable way. So, a file written by an Intel processor can be read by a
+portable way. It can be forced to read in big-endian order or
+little-endian order. So, a file written by an Intel processor can be read by a
Sparc or anything else.
\wxheading{Include files}
\section{\class{wxDataOutputStream}}\label{wxdataoutputstream}
This class provides functions that write data types in a
-portable way. So, a file written by an Intel processor can be read by a
+portable way. It can be forced to read in big-endian order or
+little-endian order. So, a file written by an Intel processor can be read by a
Sparc or anything else.
\latexignore{\rtfignore{\wxheading{Members}}}
<wx/socket.h>
+\wxheading{See also}
+
+\helpref{GSocket for wxWindows}{gsocketforwx}
+
% ---------------------------------------------------------------------------
% Event handling
% ---------------------------------------------------------------------------
% State functions
% ---------------------------------------------------------------------------
+%
+% SetFlags
+%
+
+\membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags}
+
+\func{void}{SetFlags}{\param{wxSocketBase::wxSockFlags}{ flags}}
+
+\twocolwidtha{7cm}
+\begin{twocollist}\itemsep=0pt
+\twocolitem{{\bf wxSocketBase::NONE}}{Normal functionnalities.}
+\twocolitem{{\bf wxSocketBase::NOWAIT}}{Get the available data in the input queue and exit immediately.}
+\twocolitem{{\bf wxSocketBase::WAITALL}}{Wait for all required data unless an error occured.}
+\twocolitem{{\bf wxSocketBase::SPEED}}{Disable the asynchronous IO functionnality.}
+\end{twocollist}
+
+%
+% SetNotify
+%
+\membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
+
+\func{void}{SetNotify}{\param{GSocketEventFlags}{ event_flags}}
+
+SetNotify setups which socket events are to be sent to the event handler.
+For more information on socket events see
+\helpref{GSocket events}{gsocketforwxevents}.
+
+%
+% Notify
+%
+\membersection{wxSocketBase::Notify}\label{wxsocketbasesetnotify}
+
+\func{void}{Notify}{\param{bool}{ notify}}
+
+Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
+of socket events.
+
+%
+% Ok
+%
+
\membersection{wxSocketBase::Ok}\label{wxsocketbaseok}
\constfunc{bool}{Ok}{\void}
\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
-\constfunc{int}{LastError}{\void}
+\constfunc{GSocketError}{LastError}{\void}
-Returns an error in the errno format (see your C programmer's guide).
+Returns an error in the GSocket format. See \helpref{GSocket errors}{gsocketforwxerrs}.
% ---------------------------------------------------------------------------
% IO calls
\helpref{wxSocketBase::Error}{wxsocketbaseerror},
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
-
-\membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags}
-
-\func{void}{SetFlags}{\param{wxSockFlags}{ flags}}
-
-\twocolwidtha{7cm}
-\begin{twocollist}\itemsep=0pt
-\twocolitem{{\bf wxSocketBase::NONE}}{Normal functionnalities.}
-\twocolitem{{\bf wxSocketBase::NOWAIT}}{Get the available data in the input queue and exit immediately.}
-\twocolitem{{\bf wxSocketBase::WAITALL}}{Wait for all required data unless an error occured.}
-\twocolitem{{\bf wxSocketBase::SPEED}}{Disable the asynchronous IO functionnality.}
-\end{twocollist}
%
-% Read
+% Write
%
\membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
Constructs a new wxSocketClient.
-{\bf Warning !} The new socket client needs to be registered to a socket handler (See \helpref{wxSocketHandler}{wxsockethandler}).
-
\wxheading{Parameters}
\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
\wxheading{See also}
-\helpref{wxSocketHandler}{wxsockethandler},\rtfsp
\helpref{wxSocketBase}{wxsocketbase},\rtfsp
\helpref{wxSocketClient}{wxsocketclient},\rtfsp
\helpref{wxSocketServer}{wxsocketserver}
\membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
-\constfunc{wxSocketBase::wxRequestEvent}{SocketEvent}{\void}
+\constfunc{GSocketEvent}{SocketEvent}{\void}
Returns the socket event type.
-% ---------------------------------------------------------------------------
-% CLASS: wxSocketHandler
-% ---------------------------------------------------------------------------
-\section{\class{wxSocketHandler}}\label{wxsockethandler}
-
-\wxheading{Derived from}
-
-\helpref{wxObject}{wxobject}
-
-\wxheading{Include files}
-
-<wx/socket.h>
-
-% ---------------------------------------------------------------------------
-% Members
-% ---------------------------------------------------------------------------
-\latexignore{\rtfignore{\wxheading{Members}}}
-
-%
-% wxSocketHandler
-%
-\membersection{wxSocketHandler::wxSocketHandler}
-
-\func{}{wxSocketHandler}{\void}
-
-Constructs a new wxSocketHandler.
-
-It is advised to use \helpref{wxSocketHandler::Master}{wxsockethandlermaster} to
-get a socket handler. But creating a socket handler is useful to group
-many sockets.
-
-%
-% ~wxSocketHandler
-%
-\membersection{wxSocketHandler::\destruct{wxSocketHandler}}
-
-\func{}{\destruct{wxSocketHandler}}{\void}
-
-Destroys a wxSocketHandler object.
-
-%
-% Register
-%
-\membersection{wxSocketHandler::Register}
-
-\func{void}{Register}{\param{wxSocketBase *}{socket}}
-
-Register a socket: if it is already registered in this handler it will just
-return immediately.
-
-\wxheading{Parameters}
-
-\docparam{socket}{Socket to be registered.}
-
-%
-% UnRegister
-%
-\membersection{wxSocketHandler::UnRegister}
-
-\func{void}{UnRegister}{\param{wxSocketBase *}{socket}}
-
-UnRegister a socket: if it isn't registered in this handler it will just
-return.
-
-\wxheading{Parameters}
-
-\docparam{socket}{Socket to be unregistered.}
-
-%
-% Count
-%
-\membersection{wxSocketHandler::Count}
-
-\constfunc{unsigned long}{Count}{\void}
-
-Returns the number of sockets registered in the handler.
-
-\wxheading{Return value}
-
-Number of sockets registered.
-
-%
-% CreateServer
-%
-\membersection{wxSocketHandler::CreateServer}
-
-\func{wxSocketServer *}{CreateServer}{\param{wxSockAddress\&}{ address}, \param{wxSocketBase::wxSockFlags}{ flags = wxSocketbase::NONE}}
-
-Creates a new wxSocketServer object. The object is automatically registered
-to the current socket handler.
-For a detailed description of the parameters, see \helpref{wxSocketServer::wxSocketServer}{wxsocketserverconstr}.
-
-\wxheading{Return value}
-
-Returns a new socket server.
-
-%
-% CreateClient
-%
-\membersection{wxSocketHandler::CreateClient}
-
-\func{wxSocketServer *}{CreateClient}{\param{wxSocketBase::wxSockFlags}{ flags = wxSocketbase::NONE}}
-
-Creates a new wxSocketClient object. The object is automatically registered
-to the current socket handler.
-
-For a detailed description of the parameters, see \helpref{wxSocketClient::Connect}{wxsocketclientconnect}.
-
-\wxheading{Return value}
-
-Returns a new socket client.
-
-%
-% Master
-%
-\membersection{wxSocketHandler::Master}\label{wxsockethandlermaster}
-
-\func{static wxSocketHandler\&}{Master}{\void}
-
-Returns a default socket handler.
-
-%
-% Wait
-%
-\membersection{wxSocketHandler::Wait}
-
-\func{int}{Wait}{\param{long}{ seconds},\param{long}{ microseconds}}
-
-Wait for an event on all registered sockets.
-
-\wxheading{Parameters}
-
-\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
-
-\docparam{microsecond}{Number of microseconds to wait.}
-
-\wxheading{Return value}
-
-Returns 0 if a timeout occured, else the number of events detected.
-
-\wxheading{See also}
-
-\helpref{wxSocketBase::Wait}{wxsocketbasewait}
-
-%
-% YieldSock
-%
-\membersection{wxSocketHandler::YieldSock}
-
-\func{void}{YieldSock}{\void}
-
-Execute pending requests in all registered sockets.
-
% ---------------------------------------------------------------------------
% CLASS: wxSocketServer
% ---------------------------------------------------------------------------
Constructs a new wxSocketServer.
-{\bf Warning !} The created object needs to be registered to a socket handler
-(see \helpref{wxSocketHandler}{wxsockethandler}).
-
\wxheading{Parameters}
\docparam{address}{Specifies the local address for the server (e.g. port number).}
\helpref{wxURL::SetDefaultProxy}{wxurlsetdefaultproxy}
+%
+% SetProxy
+%
+\membersection{wxURL::ConvertToValidURI}
+
+\func{static wxString}{ConvertToValidURI}{\param{const wxString\&}{ uri}}
+
+It converts a non-standardized URI to a valid network URI. It encodes non
+standard characters.
wxDataInputStream& operator>>(wxUint32& i);
wxDataInputStream& operator>>(double& i);
wxDataInputStream& operator>>(float& f);
+
+ void BidEndianOrdered(bool be_order) { m_be_order = be_order; }
protected:
wxInputStream *m_input;
+ bool m_be_order;
};
class WXDLLEXPORT wxDataOutputStream {
wxDataOutputStream& operator<<(double f);
wxDataOutputStream& operator<<(float f);
+ void BidEndianOrdered(bool be_order) { m_be_order = be_order; }
protected:
wxOutputStream *m_output;
+ bool m_be_order;
};
#endif
GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
GSocketError GAddress_INET_SetHostAddress(GAddress *address,
unsigned long hostaddr);
-GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port);
+GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
+ const char *protocol);
GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
// ---------------------------------------------------------------------------
wxDataInputStream::wxDataInputStream(wxInputStream& s)
- : m_input(&s)
+ : m_input(&s), m_be_order(FALSE)
{
}
wxUint32 wxDataInputStream::Read32()
{
- char buf[4];
+ wxUint32 i32;
- m_input->Read(buf, 4);
+ m_input->Read(&i32, 4);
- return (wxUint32)buf[0] |
- ((wxUint32)buf[1] << 8) |
- ((wxUint32)buf[2] << 16) |
- ((wxUint32)buf[3] << 24);
+ if (m_be_order)
+ return wxUINT32_SWAP_ON_LE(i32);
+ else
+ return wxUINT32_SWAP_ON_BE(i32);
}
wxUint16 wxDataInputStream::Read16()
{
- char buf[2];
+ wxUint16 i16;
- m_input->Read(buf, 2);
+ m_input->Read(&i16, 2);
- return (wxUint16)buf[0] |
- ((wxUint16)buf[1] << 8);
+ if (m_be_order)
+ return wxUINT16_SWAP_ON_LE(i16);
+ else
+ return wxUINT16_SWAP_ON_BE(i16);
}
wxUint8 wxDataInputStream::Read8()
{
wxUint8 buf;
- m_input->Read((char *)&buf, 1);
+ m_input->Read(&buf, 1);
return (wxUint8)buf;
}
void wxDataOutputStream::Write32(wxUint32 i)
{
- char buf[4];
+ wxUint32 i32;
- buf[0] = i & 0xff;
- buf[1] = (i >> 8) & 0xff;
- buf[2] = (i >> 16) & 0xff;
- buf[3] = (i >> 24) & 0xff;
- m_output->Write(buf, 4);
+ if (m_be_order)
+ i32 = wxUINT32_SWAP_ON_LE(i);
+ else
+ i32 = wxUINT32_SWAP_ON_BE(i);
+ m_output->Write(&i32, 4);
}
void wxDataOutputStream::Write16(wxUint16 i)
{
- char buf[2];
+ wxUint16 i16;
- buf[0] = i & 0xff;
- buf[1] = (i >> 8) & 0xff;
- m_output->Write(buf, 2);
+ if (m_be_order)
+ i16 = wxUINT16_SWAP_ON_LE(i);
+ else
+ i16 = wxUINT16_SWAP_ON_BE(i);
+
+ m_output->Write(&i16, 2);
}
void wxDataOutputStream::Write8(wxUint8 i)
bool wxIPV4address::Hostname(unsigned long addr)
{
- /* Need API */
- return TRUE;
+ return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR);
}
bool wxIPV4address::Service(const wxString& name)
{
- return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
+ return (GAddress_INET_SetPortName(m_address, name.fn_str(), "tcp") == GSOCK_NOERROR);
}
bool wxIPV4address::Service(unsigned short port)
return GAddress_INET_GetPort(m_address);
}
-#ifdef IPV6_ENABLE
+#if 0
// ---------------------------------------------------------------------------
// wxIPV6address
// ---------------------------------------------------------------------------
-/////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
// Name: txtstrm.cpp
// Purpose: Text stream classes
// Author: Guilhem Lavaux
for (i=0;i<uri.Len();i++) {
wxChar c = uri.GetChar(i);
- if (!isalpha(c) && c != _T('.') && c != _T('+') && c != _T('.') &&
- c != _T('/')) {
- hexa_code.Printf(_T("%%%02X"), c);
- out_str += hexa_code;
- } else
- out_str += c;
+ if (c == _T(' '))
+ out_str += _T('+');
+ else {
+ if (!isalpha(c) && c != _T('.') && c != _T('+') && c != _T('.') &&
+ c != _T('/')) {
+ hexa_code.Printf(_T("%%%02X"), c);
+ out_str += hexa_code;
+ } else
+ out_str += c;
+ }
}
return out_str;
// Name: gsockmot.cpp
// Purpose: GSocket: Motif part
// CVSID: $Id$
-// Log: $Log$
-// Log: Revision 1.1 1999/07/23 17:24:24 GL
-// Log: Added GSocket motif (it compiles but I didn't tested it)
-// Log: Changed wxSockFlags type (switched to int)
-// Log:
// -------------------------------------------------------------------------
#include <stdlib.h>
#include <X11/Intrinsic.h>
resource.cpp \
sckaddr.cpp \
sckfile.cpp \
- sckint.cpp \
sckipc.cpp \
sckstrm.cpp \
serbase.cpp \
--- /dev/null
+/* -------------------------------------------------------------------------
+ * Project: GSocket (Generic Socket) for WX
+ * Name: gsockno.c
+ * Purpose: GSocket stub GUI file
+ * CVSID: $Id$
+ * -------------------------------------------------------------------------
+ */
+#include <stdlib.h>
+#include "gsocket.h"
+
+void _GSocket_GUI_Init(GSocket *socket)
+{
+}
+
+void _GSocket_GUI_Destroy(GSocket *socket)
+{
+}
+
+void _GSocket_Install_Fallback(GSocket *socket, GSocketEvent event)
+{
+}
+
+void _GSocket_Uninstall_Fallback(GSocket *socket, GSocketEvent event)
+{
+}
+
+unsigned long GSocket_GetEventID(GSocket *socket)
+{
+ return 0;
+}
+
+void GSocket_DoEvent(unsigned long evt_id)
+{
+}
#include <stdlib.h>
#ifdef sun
-#include <sys/filio.h>
+ #include <sys/filio.h>
#endif
#ifdef sgi
#endif
#include <signal.h>
+#include <features.h>
+
#include <wx/setup.h>
#include <wx/gsocket.h>
#include "gsockunx.h"
#ifndef SOCKLEN_T
-# define SOCKLEN_T int
+
+#ifdef __GLIBC__
+# if __GLIBC__ == 2
+# define SOCKLEN_T socklen_t
+# endif
+#else
+# define SOCKLEN_T int
+#endif
+
#endif
/* Constructors / Destructors */
GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
{
- if (socket == NULL || (socket->m_fd != -1 && !socket->m_server))
+ assert(socket != NULL);
+
+ if ((socket->m_fd != -1 && !socket->m_server))
return GSOCK_INVSOCK;
if (address == NULL || address->m_family == GSOCK_NOFAMILY)
GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
{
- if (socket == NULL)
- return GSOCK_INVSOCK;
+ assert(socket != NULL);
if (address == NULL || address->m_family == GSOCK_NOFAMILY) {
socket->m_error = GSOCK_INVADDR;
GSocket_SetServer() setup the socket as a server. It uses the "Local" field
of GSocket. "Local" must be set by GSocket_SetLocal() before
GSocket_SetServer() is called. GSOCK_INVSOCK if socket has been initialized.
- In the other cases, it returns GSOCK_INVADDR.
+ In case, you haven't yet defined the local address, it returns GSOCK_INVADDR.
+ In the other cases it returns GSOCK_IOERR.
*/
GSocketError GSocket_SetServer(GSocket *sck)
{
return GSOCK_NOERROR;
}
-GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port)
+GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
+ const char *protocol)
{
struct servent *se;
struct sockaddr_in *addr;
}
/* TODO: TCP or UDP */
- se = getservbyname(port, "tcp");
+ se = getservbyname(port, protocol);
if (!se) {
if (isdigit(port[0])) {
int port_int;