]> git.saurik.com Git - wxWidgets.git/commitdiff
Updated wxDataStream (added ByteOrder)
authorGuilhem Lavaux <lavaux@easynet.fr>
Sat, 24 Jul 1999 09:05:25 +0000 (09:05 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Sat, 24 Jul 1999 09:05:25 +0000 (09:05 +0000)
Removed sckint.cpp from Makefile.am and filelist.txt (Could someone rebuild Makefile for MSW)
Some update to the documentation. I'm documenting GSocket.
Added gsockno.c in stubs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
docs/latex/wx/datstrm.tex
docs/latex/wx/socket.tex
docs/latex/wx/url.tex
include/wx/datstrm.h
include/wx/gsocket.h
src/common/datstrm.cpp
src/common/sckaddr.cpp
src/common/txtstrm.cpp
src/common/url.cpp
src/motif/gsockmot.cpp
src/msw/Makefile.am
src/stubs/gsockno.c [new file with mode: 0644]
src/unix/gsocket.c

index c33104b400d5366de9f29da46fa3ecc2ea3beefc..5aa3577443dd782b99b083547e10989e99851b6d 100644 (file)
@@ -4,7 +4,8 @@
 \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}
@@ -69,7 +70,8 @@ reads the string.
 \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}}}
index 49a59bb2275f5e27e089d1668bbc471114ee2270..d1e8d73e9d8675d694d04f78b619cd83038b687d 100644 (file)
@@ -8,6 +8,10 @@
 
 <wx/socket.h>
 
+\wxheading{See also}
+
+\helpref{GSocket for wxWindows}{gsocketforwx}
+
 % ---------------------------------------------------------------------------
 % Event handling
 % ---------------------------------------------------------------------------
@@ -53,6 +57,47 @@ Destroys the wxSocketBase object.
 % 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}
@@ -98,9 +143,9 @@ Returns the number of bytes read or written by the last IO call.
 
 \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
@@ -169,21 +214,9 @@ This remark is also valid for all IO call.
 \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}
 
@@ -489,8 +522,6 @@ Sets an event handler to be called when a socket event occured.
 
 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})}
@@ -568,7 +599,6 @@ functions that take a wxSocketEvent argument.
 
 \wxheading{See also}
 
-\helpref{wxSocketHandler}{wxsockethandler},\rtfsp
 \helpref{wxSocketBase}{wxsocketbase},\rtfsp
 \helpref{wxSocketClient}{wxsocketclient},\rtfsp
 \helpref{wxSocketServer}{wxsocketserver}
@@ -583,163 +613,10 @@ Constructor.
 
 \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
 % ---------------------------------------------------------------------------
@@ -767,9 +644,6 @@ Execute pending requests in all registered sockets.
 
 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).}
index fd05953aade22e47e01b3559c6f2862188387ed3..4f845db4be76b6808e055d7951caefd420590f5a 100644 (file)
@@ -143,3 +143,12 @@ Sets the proxy to use for this URL.
 
 \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.
index 1b38a486b375e5fbce6b96cf3af0e73936d122bf..ee557221a2e5e7ebe8650c082de22357b92cead8 100644 (file)
@@ -40,8 +40,11 @@ public:
   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 {
@@ -66,8 +69,10 @@ 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
index e060c966c36e77c9e570d2f53125b05c22e2b7f4..1de9fa618978a1a74203c39b0665026cb61a5f71 100644 (file)
@@ -189,7 +189,8 @@ GAddressType GAddress_GetFamily(GAddress *address);
 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,
index 85f80d95073dcb93a10d5923852651a7ffb922c8..5112d93f6bcd7c1aa04cfd8debe83c2a8f225229 100644 (file)
@@ -29,7 +29,7 @@
 // ---------------------------------------------------------------------------
 
 wxDataInputStream::wxDataInputStream(wxInputStream& s)
-  : m_input(&s)
+  : m_input(&s), m_be_order(FALSE)
 {
 }
 
@@ -39,31 +39,33 @@ wxDataInputStream::~wxDataInputStream()
 
 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;
 }
 
@@ -169,22 +171,25 @@ wxDataOutputStream::~wxDataOutputStream()
 
 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)
index e6f63b2ca39d6af83c38a96f952612f3c9664d6c..1e126d81afc988d951dd6d5855648791295f187e 100644 (file)
@@ -106,13 +106,12 @@ bool wxIPV4address::Hostname(const wxString& name)
 
 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)
@@ -139,7 +138,7 @@ unsigned short wxIPV4address::Service()
   return GAddress_INET_GetPort(m_address); 
 }
 
-#ifdef IPV6_ENABLE
+#if 0
 // ---------------------------------------------------------------------------
 // wxIPV6address
 // ---------------------------------------------------------------------------
index e0acaeb66c9bf62235eba8c9117a5fa6d46e593b..0522238cd782747a199dfc728846bb78ef228816 100644 (file)
@@ -1,4 +1,4 @@
-/////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 // Name:        txtstrm.cpp
 // Purpose:     Text stream classes
 // Author:      Guilhem Lavaux
index 06d802074922a130fa118246b3cb81b2e2b35d1f..956f0266f471f3415fb97a0a32797a70e3a7c5e1 100644 (file)
@@ -320,12 +320,16 @@ wxString wxURL::ConvertToValidURI(const wxString& uri)
   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;
index fa5b3d8e99e54c248cdb2c3db03310ad2e5d6f8d..af86c62dfb00fc49f100bd6ff3e68d6f2a993934 100644 (file)
@@ -3,11 +3,6 @@
 // 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>
index d9e04b110fcd9849677e63ea7aaa5628b93ce131..3fd1fc5fbbee21eb4cb0c2148a725645fa18f25f 100644 (file)
@@ -87,7 +87,6 @@ libwx_msw_la_SOURCES = \
  resource.cpp \
  sckaddr.cpp \
  sckfile.cpp \
- sckint.cpp \
  sckipc.cpp \
  sckstrm.cpp \
  serbase.cpp \
diff --git a/src/stubs/gsockno.c b/src/stubs/gsockno.c
new file mode 100644 (file)
index 0000000..94b8671
--- /dev/null
@@ -0,0 +1,34 @@
+/* -------------------------------------------------------------------------
+ * 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)
+{
+}
index f1af4f0c47aaeb43dce306ba3dcd4e691e84f1c1..74ac09de4ca6fde89a12fbdedf8eb8546c9a0981 100644 (file)
@@ -26,7 +26,7 @@
 #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 */
@@ -107,7 +117,9 @@ void GSocket_Shutdown(GSocket *socket)
 
 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)
@@ -123,8 +135,7 @@ GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
 
 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;
@@ -184,7 +195,8 @@ GAddress *GSocket_GetPeer(GSocket *socket)
   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)
 {
@@ -795,7 +807,8 @@ GSocketError GAddress_INET_SetHostAddress(GAddress *address,
   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;
@@ -809,7 +822,7 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port)
   }
  
   /* TODO: TCP or UDP */
-  se = getservbyname(port, "tcp");
+  se = getservbyname(port, protocol);
   if (!se) {
     if (isdigit(port[0])) {
       int port_int;