From 5a96d2f45fec76a2d0da1c0c7672b62c19280f43 Mon Sep 17 00:00:00 2001
From: Guilhem Lavaux <lavaux@easynet.fr>
Date: Sat, 24 Jul 1999 09:05:25 +0000
Subject: [PATCH] Updated wxDataStream (added ByteOrder) 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
---
 docs/latex/wx/datstrm.tex |   6 +-
 docs/latex/wx/socket.tex  | 224 +++++++++-----------------------------
 docs/latex/wx/url.tex     |   9 ++
 include/wx/datstrm.h      |   5 +
 include/wx/gsocket.h      |   3 +-
 src/common/datstrm.cpp    |  49 +++++----
 src/common/sckaddr.cpp    |   7 +-
 src/common/txtstrm.cpp    |   2 +-
 src/common/url.cpp        |  16 ++-
 src/motif/gsockmot.cpp    |   5 -
 src/msw/Makefile.am       |   1 -
 src/stubs/gsockno.c       |  34 ++++++
 src/unix/gsocket.c        |  29 +++--
 13 files changed, 165 insertions(+), 225 deletions(-)
 create mode 100644 src/stubs/gsockno.c

diff --git a/docs/latex/wx/datstrm.tex b/docs/latex/wx/datstrm.tex
index c33104b400..5aa3577443 100644
--- a/docs/latex/wx/datstrm.tex
+++ b/docs/latex/wx/datstrm.tex
@@ -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}}}
diff --git a/docs/latex/wx/socket.tex b/docs/latex/wx/socket.tex
index 49a59bb227..d1e8d73e9d 100644
--- a/docs/latex/wx/socket.tex
+++ b/docs/latex/wx/socket.tex
@@ -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).}
diff --git a/docs/latex/wx/url.tex b/docs/latex/wx/url.tex
index fd05953aad..4f845db4be 100644
--- a/docs/latex/wx/url.tex
+++ b/docs/latex/wx/url.tex
@@ -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.
diff --git a/include/wx/datstrm.h b/include/wx/datstrm.h
index 1b38a486b3..ee557221a2 100644
--- a/include/wx/datstrm.h
+++ b/include/wx/datstrm.h
@@ -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
diff --git a/include/wx/gsocket.h b/include/wx/gsocket.h
index e060c966c3..1de9fa6189 100644
--- a/include/wx/gsocket.h
+++ b/include/wx/gsocket.h
@@ -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,
diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp
index 85f80d9507..5112d93f6b 100644
--- a/src/common/datstrm.cpp
+++ b/src/common/datstrm.cpp
@@ -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)
diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp
index e6f63b2ca3..1e126d81af 100644
--- a/src/common/sckaddr.cpp
+++ b/src/common/sckaddr.cpp
@@ -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
 // ---------------------------------------------------------------------------
diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp
index e0acaeb66c..0522238cd7 100644
--- a/src/common/txtstrm.cpp
+++ b/src/common/txtstrm.cpp
@@ -1,4 +1,4 @@
-/////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 // Name:        txtstrm.cpp
 // Purpose:     Text stream classes
 // Author:      Guilhem Lavaux
diff --git a/src/common/url.cpp b/src/common/url.cpp
index 06d8020749..956f0266f4 100644
--- a/src/common/url.cpp
+++ b/src/common/url.cpp
@@ -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;
diff --git a/src/motif/gsockmot.cpp b/src/motif/gsockmot.cpp
index fa5b3d8e99..af86c62dfb 100644
--- a/src/motif/gsockmot.cpp
+++ b/src/motif/gsockmot.cpp
@@ -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>
diff --git a/src/msw/Makefile.am b/src/msw/Makefile.am
index d9e04b110f..3fd1fc5fbb 100644
--- a/src/msw/Makefile.am
+++ b/src/msw/Makefile.am
@@ -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
index 0000000000..94b8671139
--- /dev/null
+++ b/src/stubs/gsockno.c
@@ -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)
+{
+}
diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c
index f1af4f0c47..74ac09de4c 100644
--- a/src/unix/gsocket.c
+++ b/src/unix/gsocket.c
@@ -26,7 +26,7 @@
 #include <stdlib.h>
 
 #ifdef sun
-#include <sys/filio.h>
+  #include <sys/filio.h>
 #endif
 
 #ifdef sgi
@@ -34,12 +34,22 @@
 #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;
-- 
2.50.0

