]> git.saurik.com Git - wxWidgets.git/commitdiff
Streamline wxSocket code: wxSocketBase now uses wxSocketImpl (previously known
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Nov 2008 12:47:07 +0000 (12:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Nov 2008 12:47:07 +0000 (12:47 +0000)
as GSocket) which is a base class with various wxSocketImplXXX implementations
provided by different wxSocketManagers.

Share more code between ports (still not finished).

Refactor some code inside wxSocketImpl itself to be less redundant and fixed a
couple of minor bugs in the process.

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

27 files changed:
Makefile.in
build/bakefiles/files.bkl
include/wx/apptrait.h
include/wx/msw/apptbase.h
include/wx/msw/gsockmsw.h
include/wx/os2/apptbase.h
include/wx/os2/apptrait.h
include/wx/private/gsocket.h
include/wx/private/gsocketiohandler.h
include/wx/socket.h
include/wx/unix/app.h
include/wx/unix/apptbase.h
include/wx/unix/apptrait.h
include/wx/unix/gsockunx.h
src/common/appbase.cpp
src/common/gsocketiohandler.cpp
src/common/sckaddr.cpp
src/common/socket.cpp
src/gtk/gsockgtk.cpp
src/gtk1/gsockgtk.cpp
src/motif/gsockmot.cpp
src/msw/basemsw.cpp
src/msw/gsocket.cpp
src/msw/gsockmsw.cpp
src/os2/gsockpm.cpp
src/osx/core/gsockosx.cpp
src/unix/gsocket.cpp

index c296a05fe2b7587d73ce4a8510fe3e790e7fc302..465a6d237f6cfdf75e09427c46fd4d0005c41304 100644 (file)
@@ -27,7 +27,6 @@ STRIP = @STRIP@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 INSTALL_DIR = @INSTALL_DIR@
-ICC_PCH_USE_SWITCH = @ICC_PCH_USE_SWITCH@
 BK_DEPS = @BK_DEPS@
 BK_MAKE_PCH = @BK_MAKE_PCH@
 srcdir = @srcdir@
@@ -817,6 +816,7 @@ ALL_BASE_SOURCES =  \
        src/common/socket.cpp \
        src/common/url.cpp \
        src/unix/gsocket.cpp \
+       src/osx/core/gsockosx.cpp \
        src/msw/gsocket.cpp \
        src/msw/gsockmsw.cpp \
        src/msw/urlmsw.cpp \
@@ -1959,7 +1959,6 @@ COND_TOOLKIT__BASE_OSX_SRC =  \
        src/unix/utilsunx.cpp \
        src/unix/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp
@@ -1980,7 +1979,6 @@ COND_TOOLKIT_COCOA_BASE_OSX_SRC =  \
        src/unix/utilsunx.cpp \
        src/unix/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp
@@ -2001,7 +1999,6 @@ COND_TOOLKIT_GTK_BASE_OSX_SRC =  \
        src/unix/utilsunx.cpp \
        src/unix/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp
@@ -2022,7 +2019,6 @@ COND_TOOLKIT_MOTIF_BASE_OSX_SRC =  \
        src/unix/utilsunx.cpp \
        src/unix/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp
@@ -2030,7 +2026,6 @@ COND_TOOLKIT_MOTIF_BASE_OSX_SRC =  \
 COND_TOOLKIT_OSX_CARBON_BASE_OSX_SRC =  \
        src/osx/core/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp \
@@ -2051,7 +2046,6 @@ COND_TOOLKIT_OSX_CARBON_BASE_OSX_SRC =  \
 COND_TOOLKIT_OSX_COCOA_BASE_OSX_SRC =  \
        src/osx/core/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp \
@@ -2085,7 +2079,6 @@ COND_TOOLKIT_X11_BASE_OSX_SRC =  \
        src/unix/utilsunx.cpp \
        src/unix/mimetype.cpp \
        src/osx/core/cfstring.cpp \
-       src/osx/core/gsockosx.cpp \
        src/osx/core/stdpaths_cf.cpp \
        src/osx/core/strconv_cf.cpp \
        src/osx/core/utilsexc_base.cpp
@@ -3951,7 +3944,7 @@ COND_WINDOWS_IMPLIB_1___monodll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__monodll___importlib = $(COND_WINDOWS_IMPLIB_1___monodll___importlib)
 @COND_GCC_PCH_1@__monodll_PCH_INC = -I./.pch/wxprec_monodll
-@COND_ICC_PCH_1@__monodll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__monodll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_monodll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_monodll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_monodll/wx/wxprec.h.gch
@@ -3988,7 +3981,6 @@ COND_USE_SOSYMLINKS_1___monodll___so_symlinks_uninst_cmd = rm -f \
 COND_PLATFORM_MACOSX_1___BASE_PLATFORM_SRC_OBJECTS =  \
        monodll_core_mimetype.o \
        monodll_cfstring.o \
-       monodll_gsockosx.o \
        monodll_stdpaths_cf.o \
        monodll_strconv_cf.o \
        monodll_utilsexc_base.o \
@@ -4069,7 +4061,8 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS =  \
 @COND_TOOLKIT_OSX_CARBON@      = monodll_carbon_utils.o monodll_uma.o
 @COND_TOOLKIT_OSX_COCOA@__BASE_AND_GUI_TOOLKIT_SRC_OBJECTS \
 @COND_TOOLKIT_OSX_COCOA@       = monodll_osx_cocoa_utils.o
-@COND_PLATFORM_MACOSX_1@__NET_PLATFORM_SRC_OBJECTS = monodll_unix_gsocket.o
+@COND_PLATFORM_MACOSX_1@__NET_PLATFORM_SRC_OBJECTS \
+@COND_PLATFORM_MACOSX_1@       = monodll_unix_gsocket.o monodll_gsockosx.o
 @COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS = monodll_unix_gsocket.o
 @COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS = monodll_unix_gsocket.o
 COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS =  \
@@ -5793,14 +5786,13 @@ COND_MONOLITHIC_1_SHARED_0___monolib___depname = \
 @COND_MONOLITHIC_1_SHARED_0@__uninstall_monolib___depname \
 @COND_MONOLITHIC_1_SHARED_0@   = uninstall_monolib
 @COND_GCC_PCH_1@__monolib_PCH_INC = -I./.pch/wxprec_monolib
-@COND_ICC_PCH_1@__monolib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__monolib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_monolib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_monolib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_monolib/wx/wxprec.h.gch
 COND_PLATFORM_MACOSX_1___BASE_PLATFORM_SRC_OBJECTS_1 =  \
        monolib_core_mimetype.o \
        monolib_cfstring.o \
-       monolib_gsockosx.o \
        monolib_stdpaths_cf.o \
        monolib_strconv_cf.o \
        monolib_utilsexc_base.o \
@@ -5882,7 +5874,7 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_1 =  \
 @COND_TOOLKIT_OSX_COCOA@__BASE_AND_GUI_TOOLKIT_SRC_OBJECTS_1 \
 @COND_TOOLKIT_OSX_COCOA@       = monolib_osx_cocoa_utils.o
 @COND_PLATFORM_MACOSX_1@__NET_PLATFORM_SRC_OBJECTS_1 \
-@COND_PLATFORM_MACOSX_1@       = monolib_unix_gsocket.o
+@COND_PLATFORM_MACOSX_1@       = monolib_unix_gsocket.o monolib_gsockosx.o
 @COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_1 = monolib_unix_gsocket.o
 @COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_1 = monolib_unix_gsocket.o
 COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_1 =  \
@@ -7612,7 +7604,7 @@ COND_WINDOWS_IMPLIB_1___basedll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__basedll___importlib = $(COND_WINDOWS_IMPLIB_1___basedll___importlib)
 @COND_GCC_PCH_1@__basedll_PCH_INC = -I./.pch/wxprec_basedll
-@COND_ICC_PCH_1@__basedll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__basedll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_basedll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_basedll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_basedll/wx/wxprec.h.gch
@@ -7650,7 +7642,6 @@ COND_USE_SOSYMLINKS_1___basedll___so_symlinks_uninst_cmd = rm -f \
 COND_PLATFORM_MACOSX_1___BASE_PLATFORM_SRC_OBJECTS_2 =  \
        basedll_core_mimetype.o \
        basedll_cfstring.o \
-       basedll_gsockosx.o \
        basedll_stdpaths_cf.o \
        basedll_strconv_cf.o \
        basedll_utilsexc_base.o \
@@ -7738,14 +7729,13 @@ COND_MONOLITHIC_0_SHARED_0___baselib___depname = \
 @COND_MONOLITHIC_0_SHARED_0@__uninstall_baselib___depname \
 @COND_MONOLITHIC_0_SHARED_0@   = uninstall_baselib
 @COND_GCC_PCH_1@__baselib_PCH_INC = -I./.pch/wxprec_baselib
-@COND_ICC_PCH_1@__baselib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__baselib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_baselib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_baselib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_baselib/wx/wxprec.h.gch
 COND_PLATFORM_MACOSX_1___BASE_PLATFORM_SRC_OBJECTS_3 =  \
        baselib_core_mimetype.o \
        baselib_cfstring.o \
-       baselib_gsockosx.o \
        baselib_stdpaths_cf.o \
        baselib_strconv_cf.o \
        baselib_utilsexc_base.o \
@@ -7843,7 +7833,7 @@ COND_WINDOWS_IMPLIB_1___netdll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_net-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__netdll___importlib = $(COND_WINDOWS_IMPLIB_1___netdll___importlib)
 @COND_GCC_PCH_1@__netdll_PCH_INC = -I./.pch/wxprec_netdll
-@COND_ICC_PCH_1@__netdll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__netdll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_netdll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_netdll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_netdll/wx/wxprec.h.gch
@@ -7879,7 +7869,7 @@ COND_USE_SOSYMLINKS_1___netdll___so_symlinks_uninst_cmd = rm -f \
 @COND_USE_SOSYMLINKS_1@__netdll___so_symlinks_uninst_cmd = $(COND_USE_SOSYMLINKS_1___netdll___so_symlinks_uninst_cmd)
 @COND_PLATFORM_WIN32_1@__netdll___win32rc = netdll_version_rc.o
 @COND_PLATFORM_MACOSX_1@__NET_PLATFORM_SRC_OBJECTS_2 \
-@COND_PLATFORM_MACOSX_1@       = netdll_unix_gsocket.o
+@COND_PLATFORM_MACOSX_1@       = netdll_unix_gsocket.o netdll_gsockosx.o
 @COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_2 = netdll_unix_gsocket.o
 @COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_2 = netdll_unix_gsocket.o
 COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_2 =  \
@@ -7895,12 +7885,12 @@ COND_MONOLITHIC_0_SHARED_0___netlib___depname = \
 @COND_MONOLITHIC_0_SHARED_0@__install_netlib___depname = install_netlib
 @COND_MONOLITHIC_0_SHARED_0@__uninstall_netlib___depname = uninstall_netlib
 @COND_GCC_PCH_1@__netlib_PCH_INC = -I./.pch/wxprec_netlib
-@COND_ICC_PCH_1@__netlib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__netlib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_netlib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_netlib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_netlib/wx/wxprec.h.gch
 @COND_PLATFORM_MACOSX_1@__NET_PLATFORM_SRC_OBJECTS_3 \
-@COND_PLATFORM_MACOSX_1@       = netlib_unix_gsocket.o
+@COND_PLATFORM_MACOSX_1@       = netlib_unix_gsocket.o netlib_gsockosx.o
 @COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_3 = netlib_unix_gsocket.o
 @COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_3 = netlib_unix_gsocket.o
 COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_3 =  \
@@ -7929,7 +7919,7 @@ COND_WINDOWS_IMPLIB_1___coredll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__coredll___importlib = $(COND_WINDOWS_IMPLIB_1___coredll___importlib)
 @COND_GCC_PCH_1@__coredll_PCH_INC = -I./.pch/wxprec_coredll
-@COND_ICC_PCH_1@__coredll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__coredll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_coredll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_coredll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_coredll/wx/wxprec.h.gch
@@ -9464,7 +9454,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1___corelib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1@__uninstall_corelib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1@ = uninstall_corelib
 @COND_GCC_PCH_1@__corelib_PCH_INC = -I./.pch/wxprec_corelib
-@COND_ICC_PCH_1@__corelib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__corelib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_corelib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_corelib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_corelib/wx/wxprec.h.gch
@@ -10979,7 +10969,7 @@ COND_WINDOWS_IMPLIB_1___advdll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_adv-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__advdll___importlib = $(COND_WINDOWS_IMPLIB_1___advdll___importlib)
 @COND_GCC_PCH_1@__advdll_PCH_INC = -I./.pch/wxprec_advdll
-@COND_ICC_PCH_1@__advdll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__advdll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_advdll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_advdll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_advdll/wx/wxprec.h.gch
@@ -11100,7 +11090,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1___advlib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1@__uninstall_advlib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1@ = uninstall_advlib
 @COND_GCC_PCH_1@__advlib_PCH_INC = -I./.pch/wxprec_advlib
-@COND_ICC_PCH_1@__advlib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__advlib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_advlib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_advlib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_advlib/wx/wxprec.h.gch
@@ -11201,7 +11191,7 @@ COND_WINDOWS_IMPLIB_1___mediadll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_media-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__mediadll___importlib = $(COND_WINDOWS_IMPLIB_1___mediadll___importlib)
 @COND_GCC_PCH_1@__mediadll_PCH_INC = -I./.pch/wxprec_mediadll
-@COND_ICC_PCH_1@__mediadll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__mediadll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_mediadll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_mediadll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_mediadll/wx/wxprec.h.gch
@@ -11268,7 +11258,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_MEDIA_1___medialib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_MEDIA_1@__uninstall_medialib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_MEDIA_1@     = uninstall_medialib
 @COND_GCC_PCH_1@__medialib_PCH_INC = -I./.pch/wxprec_medialib
-@COND_ICC_PCH_1@__medialib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__medialib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_medialib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_medialib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_medialib/wx/wxprec.h.gch
@@ -11315,7 +11305,7 @@ COND_WINDOWS_IMPLIB_1___htmldll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_html-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__htmldll___importlib = $(COND_WINDOWS_IMPLIB_1___htmldll___importlib)
 @COND_GCC_PCH_1@__htmldll_PCH_INC = -I./.pch/wxprec_htmldll
-@COND_ICC_PCH_1@__htmldll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__htmldll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_htmldll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_htmldll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_htmldll/wx/wxprec.h.gch
@@ -11361,7 +11351,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_HTML_1___htmllib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_HTML_1@__uninstall_htmllib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_HTML_1@      = uninstall_htmllib
 @COND_GCC_PCH_1@__htmllib_PCH_INC = -I./.pch/wxprec_htmllib
-@COND_ICC_PCH_1@__htmllib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__htmllib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_htmllib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_htmllib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_htmllib/wx/wxprec.h.gch
@@ -11387,7 +11377,7 @@ COND_WINDOWS_IMPLIB_1___qadll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_qa-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__qadll___importlib = $(COND_WINDOWS_IMPLIB_1___qadll___importlib)
 @COND_GCC_PCH_1@__qadll_PCH_INC = -I./.pch/wxprec_qadll
-@COND_ICC_PCH_1@__qadll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__qadll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_qadll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_qadll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_qadll/wx/wxprec.h.gch
@@ -11430,7 +11420,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_QA_1___qalib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_QA_1@__uninstall_qalib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_QA_1@        = uninstall_qalib
 @COND_GCC_PCH_1@__qalib_PCH_INC = -I./.pch/wxprec_qalib
-@COND_ICC_PCH_1@__qalib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__qalib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_qalib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_qalib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_qalib/wx/wxprec.h.gch
@@ -11451,7 +11441,7 @@ COND_WINDOWS_IMPLIB_1___xmldll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_xml-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__xmldll___importlib = $(COND_WINDOWS_IMPLIB_1___xmldll___importlib)
 @COND_GCC_PCH_1@__xmldll_PCH_INC = -I./.pch/wxprec_xmldll
-@COND_ICC_PCH_1@__xmldll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__xmldll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_xmldll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_xmldll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_xmldll/wx/wxprec.h.gch
@@ -11492,7 +11482,7 @@ COND_MONOLITHIC_0_SHARED_0___xmllib___depname = \
 @COND_MONOLITHIC_0_SHARED_0@__install_xmllib___depname = install_xmllib
 @COND_MONOLITHIC_0_SHARED_0@__uninstall_xmllib___depname = uninstall_xmllib
 @COND_GCC_PCH_1@__xmllib_PCH_INC = -I./.pch/wxprec_xmllib
-@COND_ICC_PCH_1@__xmllib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__xmllib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_xmllib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_xmllib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_xmllib/wx/wxprec.h.gch
@@ -11515,7 +11505,7 @@ COND_WINDOWS_IMPLIB_1___xrcdll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_xrc-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__xrcdll___importlib = $(COND_WINDOWS_IMPLIB_1___xrcdll___importlib)
 @COND_GCC_PCH_1@__xrcdll_PCH_INC = -I./.pch/wxprec_xrcdll
-@COND_ICC_PCH_1@__xrcdll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__xrcdll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_xrcdll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_xrcdll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_xrcdll/wx/wxprec.h.gch
@@ -11558,7 +11548,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_XRC_1___xrclib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_XRC_1@__uninstall_xrclib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_XRC_1@ = uninstall_xrclib
 @COND_GCC_PCH_1@__xrclib_PCH_INC = -I./.pch/wxprec_xrclib
-@COND_ICC_PCH_1@__xrclib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__xrclib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_xrclib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_xrclib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_xrclib/wx/wxprec.h.gch
@@ -11581,7 +11571,7 @@ COND_WINDOWS_IMPLIB_1___auidll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_aui-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__auidll___importlib = $(COND_WINDOWS_IMPLIB_1___auidll___importlib)
 @COND_GCC_PCH_1@__auidll_PCH_INC = -I./.pch/wxprec_auidll
-@COND_ICC_PCH_1@__auidll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__auidll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_auidll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_auidll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_auidll/wx/wxprec.h.gch
@@ -11624,7 +11614,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_AUI_1___auilib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_AUI_1@__uninstall_auilib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_AUI_1@ = uninstall_auilib
 @COND_GCC_PCH_1@__auilib_PCH_INC = -I./.pch/wxprec_auilib
-@COND_ICC_PCH_1@__auilib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__auilib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_auilib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_auilib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_auilib/wx/wxprec.h.gch
@@ -11647,8 +11637,7 @@ COND_WINDOWS_IMPLIB_1___propgriddll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_propgrid-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__propgriddll___importlib = $(COND_WINDOWS_IMPLIB_1___propgriddll___importlib)
 @COND_GCC_PCH_1@__propgriddll_PCH_INC = -I./.pch/wxprec_propgriddll
-@COND_ICC_PCH_1@__propgriddll_PCH_INC = \
-@COND_ICC_PCH_1@       $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__propgriddll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_propgriddll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_propgriddll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_propgriddll/wx/wxprec.h.gch
@@ -11692,8 +11681,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_PROPGRID_1___propgridlib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_PROPGRID_1@__uninstall_propgridlib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_PROPGRID_1@    = uninstall_propgridlib
 @COND_GCC_PCH_1@__propgridlib_PCH_INC = -I./.pch/wxprec_propgridlib
-@COND_ICC_PCH_1@__propgridlib_PCH_INC = \
-@COND_ICC_PCH_1@       $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__propgridlib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_propgridlib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_propgridlib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_propgridlib/wx/wxprec.h.gch
@@ -11716,8 +11704,7 @@ COND_WINDOWS_IMPLIB_1___richtextdll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_richtext-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__richtextdll___importlib = $(COND_WINDOWS_IMPLIB_1___richtextdll___importlib)
 @COND_GCC_PCH_1@__richtextdll_PCH_INC = -I./.pch/wxprec_richtextdll
-@COND_ICC_PCH_1@__richtextdll_PCH_INC = \
-@COND_ICC_PCH_1@       $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__richtextdll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_richtextdll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_richtextdll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_richtextdll/wx/wxprec.h.gch
@@ -11761,8 +11748,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_RICHTEXT_1___richtextlib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_RICHTEXT_1@__uninstall_richtextlib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_RICHTEXT_1@    = uninstall_richtextlib
 @COND_GCC_PCH_1@__richtextlib_PCH_INC = -I./.pch/wxprec_richtextlib
-@COND_ICC_PCH_1@__richtextlib_PCH_INC = \
-@COND_ICC_PCH_1@       $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__richtextlib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_richtextlib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_richtextlib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_richtextlib/wx/wxprec.h.gch
@@ -11785,7 +11771,7 @@ COND_WINDOWS_IMPLIB_1___stcdll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_stc-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__stcdll___importlib = $(COND_WINDOWS_IMPLIB_1___stcdll___importlib)
 @COND_GCC_PCH_1@__stcdll_PCH_INC = -I./.pch/wxprec_stcdll
-@COND_ICC_PCH_1@__stcdll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__stcdll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_stcdll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_stcdll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_stcdll/wx/wxprec.h.gch
@@ -11828,7 +11814,7 @@ COND_MONOLITHIC_0_SHARED_0_USE_STC_1___stclib___depname = \
 @COND_MONOLITHIC_0_SHARED_0_USE_STC_1@__uninstall_stclib___depname \
 @COND_MONOLITHIC_0_SHARED_0_USE_STC_1@ = uninstall_stclib
 @COND_GCC_PCH_1@__stclib_PCH_INC = -I./.pch/wxprec_stclib
-@COND_ICC_PCH_1@__stclib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__stclib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_stclib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_stclib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_stclib/wx/wxprec.h.gch
@@ -11851,7 +11837,7 @@ COND_WINDOWS_IMPLIB_1___gldll___importlib = \
        -Wl,--out-implib=$(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_WINDOWS_IMPLIB_1@__gldll___importlib = $(COND_WINDOWS_IMPLIB_1___gldll___importlib)
 @COND_GCC_PCH_1@__gldll_PCH_INC = -I./.pch/wxprec_gldll
-@COND_ICC_PCH_1@__gldll_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__gldll_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_gldll/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_gldll_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_gldll/wx/wxprec.h.gch
@@ -11920,7 +11906,7 @@ COND_SHARED_0_USE_GUI_1_USE_OPENGL_1___gllib___depname = \
 @COND_SHARED_0_USE_GUI_1_USE_OPENGL_1@__uninstall_gllib___depname \
 @COND_SHARED_0_USE_GUI_1_USE_OPENGL_1@ = uninstall_gllib
 @COND_GCC_PCH_1@__gllib_PCH_INC = -I./.pch/wxprec_gllib
-@COND_ICC_PCH_1@__gllib_PCH_INC = $(ICC_PCH_USE_SWITCH) \
+@COND_ICC_PCH_1@__gllib_PCH_INC = -use_pch \
 @COND_ICC_PCH_1@       ./.pch/wxprec_gllib/wx/wxprec.h.gch
 @COND_USE_PCH_1@_____pch_wxprec_gllib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@       = ./.pch/wxprec_gllib/wx/wxprec.h.gch
@@ -14445,9 +14431,6 @@ monodll_core_mimetype.o: $(srcdir)/src/osx/core/mimetype.cpp $(MONODLL_ODEP)
 monodll_cfstring.o: $(srcdir)/src/osx/core/cfstring.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/cfstring.cpp
 
-monodll_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(MONODLL_ODEP)
-       $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
-
 monodll_stdpaths_cf.o: $(srcdir)/src/osx/core/stdpaths_cf.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/stdpaths_cf.cpp
 
@@ -14559,6 +14542,9 @@ monodll_urlmsw.o: $(srcdir)/src/msw/urlmsw.cpp $(MONODLL_ODEP)
 monodll_net.o: $(srcdir)/src/msw/wince/net.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/wince/net.cpp
 
+monodll_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(MONODLL_ODEP)
+       $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
+
 monodll_graphicc.o: $(srcdir)/src/generic/graphicc.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/graphicc.cpp
 
@@ -19125,9 +19111,6 @@ monolib_core_mimetype.o: $(srcdir)/src/osx/core/mimetype.cpp $(MONOLIB_ODEP)
 monolib_cfstring.o: $(srcdir)/src/osx/core/cfstring.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/cfstring.cpp
 
-monolib_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(MONOLIB_ODEP)
-       $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
-
 monolib_stdpaths_cf.o: $(srcdir)/src/osx/core/stdpaths_cf.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/stdpaths_cf.cpp
 
@@ -19239,6 +19222,9 @@ monolib_urlmsw.o: $(srcdir)/src/msw/urlmsw.cpp $(MONOLIB_ODEP)
 monolib_net.o: $(srcdir)/src/msw/wince/net.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/wince/net.cpp
 
+monolib_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(MONOLIB_ODEP)
+       $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
+
 monolib_graphicc.o: $(srcdir)/src/generic/graphicc.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/graphicc.cpp
 
@@ -23805,9 +23791,6 @@ basedll_core_mimetype.o: $(srcdir)/src/osx/core/mimetype.cpp $(BASEDLL_ODEP)
 basedll_cfstring.o: $(srcdir)/src/osx/core/cfstring.cpp $(BASEDLL_ODEP)
        $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/osx/core/cfstring.cpp
 
-basedll_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(BASEDLL_ODEP)
-       $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
-
 basedll_stdpaths_cf.o: $(srcdir)/src/osx/core/stdpaths_cf.cpp $(BASEDLL_ODEP)
        $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/osx/core/stdpaths_cf.cpp
 
@@ -24270,9 +24253,6 @@ baselib_core_mimetype.o: $(srcdir)/src/osx/core/mimetype.cpp $(BASELIB_ODEP)
 baselib_cfstring.o: $(srcdir)/src/osx/core/cfstring.cpp $(BASELIB_ODEP)
        $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/osx/core/cfstring.cpp
 
-baselib_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(BASELIB_ODEP)
-       $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
-
 baselib_stdpaths_cf.o: $(srcdir)/src/osx/core/stdpaths_cf.cpp $(BASELIB_ODEP)
        $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/osx/core/stdpaths_cf.cpp
 
@@ -24486,6 +24466,9 @@ netdll_urlmsw.o: $(srcdir)/src/msw/urlmsw.cpp $(NETDLL_ODEP)
 netdll_net.o: $(srcdir)/src/msw/wince/net.cpp $(NETDLL_ODEP)
        $(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/msw/wince/net.cpp
 
+netdll_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(NETDLL_ODEP)
+       $(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
+
 @COND_PLATFORM_UNIX_1@netdll_unix_gsocket.o: $(srcdir)/src/unix/gsocket.cpp $(NETDLL_ODEP)
 @COND_PLATFORM_UNIX_1@ $(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/unix/gsocket.cpp
 
@@ -24537,6 +24520,9 @@ netlib_urlmsw.o: $(srcdir)/src/msw/urlmsw.cpp $(NETLIB_ODEP)
 netlib_net.o: $(srcdir)/src/msw/wince/net.cpp $(NETLIB_ODEP)
        $(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/msw/wince/net.cpp
 
+netlib_gsockosx.o: $(srcdir)/src/osx/core/gsockosx.cpp $(NETLIB_ODEP)
+       $(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/osx/core/gsockosx.cpp
+
 @COND_PLATFORM_UNIX_1@netlib_unix_gsocket.o: $(srcdir)/src/unix/gsocket.cpp $(NETLIB_ODEP)
 @COND_PLATFORM_UNIX_1@ $(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/unix/gsocket.cpp
 
index eeb9b500ff2ea7a39a15c3ae60bf91c0633657a3..1b394716566c58b22d37b80b879b83b6531429f8 100644 (file)
@@ -184,7 +184,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
 <!-- Used on Mac OS X wxMac base, and Mac OS X darwin base -->
 <set var="BASE_COREFOUNDATION_SRC" hints="files">
     src/osx/core/cfstring.cpp
-    src/osx/core/gsockosx.cpp
     src/osx/core/stdpaths_cf.cpp
     src/osx/core/strconv_cf.cpp
     src/osx/core/utilsexc_base.cpp
@@ -547,6 +546,10 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/unix/gsockunx.h
 </set>
 
+<set var="NET_OSX_SRC" hints="files">
+    src/osx/core/gsockosx.cpp
+</set>
+
 <set var="NET_WIN32_SRC" hints="files">
     src/msw/gsocket.cpp
     src/msw/gsockmsw.cpp
@@ -3615,7 +3618,7 @@ src/osx/iphone/window.mm
     <set var="NET_PLATFORM_SRC" hints="files">
         <if cond="PLATFORM_UNIX=='1'">$(NET_UNIX_SRC)</if>
         <if cond="PLATFORM_WIN32=='1'">$(NET_WIN32_SRC) $(NET_WINCE_SRC)</if>
-        <if cond="PLATFORM_MACOSX=='1'">$(NET_UNIX_SRC)</if>
+        <if cond="PLATFORM_MACOSX=='1'">$(NET_UNIX_SRC) $(NET_OSX_SRC)</if>
         <if cond="PLATFORM_OS2=='1'">$(NET_OS2_SRC)</if>
     </set>
     <set var="NET_PLATFORM_HDR" hints="files">
@@ -3828,7 +3831,8 @@ src/osx/iphone/window.mm
         $(BASE_AND_GUI_OSX_CARBON_SRC)
         $(BASE_AND_GUI_OSX_COCOA_SRC)
         $(BASE_AND_GUI_WIN32_SRC)
-        $(NET_CMN_SRC) $(NET_UNIX_SRC) $(NET_WIN32_SRC) $(NET_WINCE_SRC)
+        $(NET_CMN_SRC) $(NET_UNIX_SRC) $(NET_OSX_SRC)
+        $(NET_WIN32_SRC) $(NET_WINCE_SRC)
         $(XML_SRC)
     </set>
 
index c31d9d0670ea770429472e513a2cc62b8521e381..cbc3867147e08fa328421dd8f7400b07cacf1e29 100644 (file)
@@ -30,7 +30,7 @@ class WXDLLIMPEXP_FWD_BASE wxString;
 class WXDLLIMPEXP_FWD_BASE wxTimer;
 class WXDLLIMPEXP_FWD_BASE wxTimerImpl;
 
-class GSocketManager;
+class wxSocketManager;
 
 
 // ----------------------------------------------------------------------------
@@ -116,9 +116,21 @@ public:
     virtual void RemoveFromPendingDelete(wxObject *object) = 0;
 
 #if wxUSE_SOCKETS
+    // this function is used by wxNet library to set the default socket manager
+    // to use: doing it like this allows us to keep all socket-related code in
+    // wxNet instead of having to pull it in wxBase itself as we'd have to do
+    // if we really implemented wxSocketManager here
+    //
+    // we don't take ownership of this pointer, it should have a lifetime
+    // greater than that of any socket (e.g. be a pointer to a static object)
+    static void SetDefaultSocketManager(wxSocketManager *manager)
+    {
+        ms_manager = manager;
+    }
+
     // return socket manager: this is usually different for console and GUI
     // applications (although some ports use the same implementation for both)
-    virtual GSocketManager *GetSocketManager() = 0;
+    virtual wxSocketManager *GetSocketManager() { return ms_manager; }
 #endif
 
     // create a new, port specific, instance of the event loop used by wxApp
@@ -169,6 +181,9 @@ protected:
     // utility function: returns the stack frame as a plain wxString
     virtual wxString GetAssertStackTrace();
 #endif
+
+private:
+    static wxSocketManager *ms_manager;
 };
 
 // ----------------------------------------------------------------------------
index 851b28c856d7efc1c7da1403af373f33fe184278..6aba6b4ae3e2c9f572b7f694d8132fba6c108257 100644 (file)
@@ -46,26 +46,6 @@ public:
     virtual WXDWORD WaitForThread(WXHANDLE hThread) = 0;
 
 
-    // wxSocket support
-    // ----------------
-
-#if wxUSE_SOCKETS
-    // this function is used by wxNet library to set the default socket manager
-    // to use: doing it like this allows us to keep all socket-related code in
-    // wxNet instead of having to pull it in wxBase itself as we'd have to do
-    // if we really implemented GSocketManager here
-    //
-    // we don't take ownership of this pointer, it should have a lifetime
-    // greater than that of any socket (e.g. be a pointer to a static object)
-    static void SetDefaultSocketManager(GSocketManager *manager)
-    {
-        ms_manager = manager;
-    }
-
-    virtual GSocketManager *GetSocketManager() { return ms_manager; }
-#endif // wxUSE_SOCKETS
-
-
 #ifndef __WXWINCE__
     // console helpers
     // ---------------
@@ -86,8 +66,6 @@ protected:
     // implementation of WaitForThread() for the console applications which is
     // also used by the GUI code if it doesn't [yet|already} dispatch events
     WXDWORD DoSimpleWaitForThread(WXHANDLE hThread);
-
-    static GSocketManager *ms_manager;
 };
 
 #endif // _WX_MSW_APPTBASE_H_
index 3fbd6ac1aa1b658e5864ce241b531e0fc5a1a341..fe5d5a2942c35c8228ce200b33a8e6e01e78eacf 100644 (file)
@@ -1,12 +1,15 @@
-/* -------------------------------------------------------------------------
- * Project:     GSocket (Generic Socket) for WX
- * Name:        gsockmsw.h
- * Copyright:   (c) Guilhem Lavaux
- * Licence:     wxWindows Licence
- * Purpose:     GSocket MSW header
- * CVSID:       $Id$
- * -------------------------------------------------------------------------
- */
+/////////////////////////////////////////////////////////////////////////////
+// Name:       wx/msw/gsockmsw.h
+// Purpose:    MSW-specific socket implementation
+// Authors:    Guilhem Lavaux, Guillermo Rodriguez Garcia, Vadim Zeitlin
+// Created:    April 1997
+// Copyright:  (C) 1999-1997, Guilhem Lavaux
+//             (C) 1999-2000, Guillermo Rodriguez Garcia
+//             (C) 2008 Vadim Zeitlin
+// RCS_ID:     $Id$
+// License:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
 
 #ifndef _WX_MSW_GSOCKMSW_H_
 #define _WX_MSW_GSOCKMSW_H_
 #endif
 
 #if defined(__WXWINCE__) || defined(__CYGWIN__)
-#include <winsock.h>
+    #include <winsock.h>
 #endif
 
-/* Definition of GSocket */
-class GSocket : public GSocketBase
+// ----------------------------------------------------------------------------
+// MSW-specific socket implementation
+// ----------------------------------------------------------------------------
+
+class wxSocketImplMSW : public wxSocketImpl
 {
 public:
-    GSocket(wxSocketBase& wxsocket)
-        : GSocketBase(wxsocket)
+    wxSocketImplMSW(wxSocketBase& wxsocket);
+
+    virtual ~wxSocketImplMSW();
+
+    virtual wxSocketImpl *WaitConnection(wxSocketBase& wxsocket);
+
+
+    int Read(char *buffer, int size);
+    int Write(const char *buffer, int size);
+
+private:
+    virtual wxSocketError DoHandleConnect(int ret);
+    virtual void DoClose();
+
+    virtual void UnblockAndRegisterWithEventLoop()
     {
-        m_msgnumber = 0;
+        // no need to make the socket non-blocking, Install_Callback() will do
+        // it
+        wxSocketManager::Get()->Install_Callback(this);
     }
 
-    virtual GSocket *WaitConnection(wxSocketBase& wxsocket);
-
-
-  GSocketError SetServer();
-
-  // not used under MSW
-  void Notify(bool) { }
-  bool SetReusable();
-  bool SetBroadcast();
-  bool DontDoBind();
-  GSocketError Connect(GSocketStream stream);
-  GSocketError SetNonOriented();
-  int Read(char *buffer, int size);
-  int Write(const char *buffer, int size);
-  void SetNonBlocking(bool non_block);
-  GSocketError WXDLLIMPEXP_NET GetError();
-  GSocketError GetSockOpt(int level, int optname,
-    void *optval, int *optlen);
-  GSocketError SetSockOpt(int level, int optname,
-    const void *optval, int optlen);
-
-protected:
-  GSocketError Input_Timeout();
-  GSocketError Output_Timeout();
-  GSocketError Connect_Timeout();
-  int Recv_Stream(char *buffer, int size);
-  int Recv_Dgram(char *buffer, int size);
-  int Send_Stream(const char *buffer, int size);
-  int Send_Dgram(const char *buffer, int size);
-
-/* TODO: Make these protected */
-public:
+    wxSocketError Input_Timeout();
+    wxSocketError Output_Timeout();
+    wxSocketError Connect_Timeout();
+    int Recv_Stream(char *buffer, int size);
+    int Recv_Dgram(char *buffer, int size);
+    int Send_Stream(const char *buffer, int size);
+    int Send_Dgram(const char *buffer, int size);
+
+    int m_msgnumber;
+
+    friend class wxSocketMSWManager;
 
-  int m_msgnumber;
+    DECLARE_NO_COPY_CLASS(wxSocketImplMSW)
 };
 
 #endif  /* _WX_MSW_GSOCKMSW_H_ */
index 4694aff2dd584409960f338627a0612fee0593d6..5916fda07dbc92658ebb8c045fe51db3cc043fbc 100644 (file)
@@ -31,7 +31,7 @@ public:
     // returns the select()-based socket manager for console applications which
     // is also used by some ports (wxX11, wxDFB) in the GUI build (hence it is
     // here and not in wxConsoleAppTraits)
-    virtual GSocketManager *GetSocketManager();
+    virtual wxSocketManager *GetSocketManager();
 #endif
 };
 
index cd9fa56e54c7ffbfbeb4dd84fc2528a2a19324b9..4038e880941428eaf6444dc229cead68189790da 100644 (file)
@@ -50,7 +50,7 @@ public:
     virtual wxString GetDesktopEnvironment() const;
 #endif
 #if wxUSE_SOCKETS
-    virtual GSocketManager *GetSocketManager();
+    virtual wxSocketManager *GetSocketManager();
 #endif
 };
 
index f8379003edde6cfed8fda00218d8652fc6203647..c70fab41683b26bc50cfc8b19209c3b597b03627 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        wx/private/gsocket.h
-// Purpose:     GSocket implementation
+// Purpose:     wxSocketImpl nd related declarations
 // Authors:     Guilhem Lavaux, Vadim Zeitlin
 // Created:     April 1997
 // RCS-ID:      $Id$
@@ -9,6 +9,31 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
+/*
+    Brief overview of different socket classes:
+
+    - wxSocketBase is the public class representing a socket ("Base" here
+      refers to the fact that wxSocketClient and wxSocketServer are derived
+      from it and predates the convention of using "Base" for common base
+      classes for platform-specific classes in wxWidgets) with implementation
+      common to all platforms and forwarding methods whose implementation
+      differs between platforms to wxSocketImpl which it contains.
+
+    - wxSocketImpl is actually just an abstract base class having only code
+      common to all platforms, the concrete implementation classes derive from
+      it and are created by wxSocketManager::CreateSocket().
+
+    - Some socket operations have different implementations in console-mode and
+      GUI applications. wxSocketManager class exists to abstract this in such
+      way that console applications (using wxBase) don't depend on wxNet. An
+      object of this class is made available via wxApp and GUI applications set
+      up a different kind of global socket manager from console ones.
+
+      TODO: it looks like wxSocketManager could be eliminated by providing
+            methods for registering/unregistering sockets directly in
+            wxEventLoop.
+ */
+
 #ifndef _WX_PRIVATE_GSOCKET_H_
 #define _WX_PRIVATE_GSOCKET_H_
 
@@ -16,9 +41,7 @@
 
 #if wxUSE_SOCKETS
 
-#include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
-
-class WXDLLIMPEXP_FWD_NET wxSocketBase;
+#include "wx/socket.h"
 
 #include <stddef.h>
 
@@ -43,61 +66,48 @@ class WXDLLIMPEXP_FWD_NET wxSocketBase;
     #include <sys/time.h>   // for timeval
 #endif
 
-enum GAddressType
-{
-  GSOCK_NOFAMILY = 0,
-  GSOCK_INET,
-  GSOCK_INET6,
-  GSOCK_UNIX
-};
+// these definitions are for MSW when we don't use configure, otherwise these
+// symbols are defined by configure
+#ifndef WX_SOCKLEN_T
+    #define WX_SOCKLEN_T int
+#endif
 
-enum GSocketStream
-{
-  GSOCK_STREAMED,
-  GSOCK_UNSTREAMED
-};
+#ifndef SOCKOPTLEN_T
+    #define SOCKOPTLEN_T int
+#endif
 
-enum GSocketError
-{
-  GSOCK_NOERROR = 0,
-  GSOCK_INVOP,
-  GSOCK_IOERR,
-  GSOCK_INVADDR,
-  GSOCK_INVSOCK,
-  GSOCK_NOHOST,
-  GSOCK_INVPORT,
-  GSOCK_WOULDBLOCK,
-  GSOCK_TIMEDOUT,
-  GSOCK_MEMERR,
-  GSOCK_OPTERR
-};
+// define some symbols which winsock.h defines but traditional BSD headers
+// don't
+#ifndef SOCKET
+    #define SOCKET int
+#endif
 
-/* See below for an explanation on how events work.
- */
-enum GSocketEvent
-{
-  GSOCK_INPUT  = 0,
-  GSOCK_OUTPUT = 1,
-  GSOCK_CONNECTION = 2,
-  GSOCK_LOST = 3,
-  GSOCK_MAX_EVENT = 4
-};
+#ifndef INVALID_SOCKET
+    #define INVALID_SOCKET (-1)
+#endif
+
+#ifndef SOCKET_ERROR
+    #define SOCKET_ERROR (-1)
+#endif
 
-enum
+#if wxUSE_IPV6
+    typedef struct sockaddr_storage wxSockAddr;
+#else
+    typedef struct sockaddr wxSockAddr;
+#endif
+
+enum GAddressType
 {
-  GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
-  GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
-  GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
-  GSOCK_LOST_FLAG = 1 << GSOCK_LOST
+    wxSOCKET_NOFAMILY = 0,
+    wxSOCKET_INET,
+    wxSOCKET_INET6,
+    wxSOCKET_UNIX
 };
 
-typedef int GSocketEventFlags;
+typedef int wxSocketEventFlags;
 
 struct GAddress;
-class GSocket;
-
-typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
-                                char *cdata);
+class wxSocketImpl;
 
 /*
    Class providing hooks abstracting the differences between console and GUI
@@ -108,23 +118,23 @@ typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
    its existence is that we want the same socket code work differently
    depending on whether it's used from a console or a GUI program. This is
    achieved by implementing the virtual methods of this class differently in
-   the objects returned by wxConsoleAppTraits::GetSocketFunctionsTable() and
-   the same method in wxGUIAppTraits.
+   the objects returned by wxConsoleAppTraits::GetSocketManager() and the same
+   method in wxGUIAppTraits.
  */
-class GSocketManager
+class wxSocketManager
 {
 public:
     // set the manager to use, we don't take ownership of it
     //
-    // this should be called before GSocket_Init(), i.e. before the first
-    // wxSocket object is created, otherwise the manager returned by
-    // wxAppTraits::GetSocketManager() will be used
-    static void Set(GSocketManager *manager);
+    // this should be called before creating the first wxSocket object,
+    // otherwise the manager returned by wxAppTraits::GetSocketManager() will
+    // be used
+    static void Set(wxSocketManager *manager);
 
     // return the manager to use
     //
     // this initializes the manager at first use
-    static GSocketManager *Get()
+    static wxSocketManager *Get()
     {
         if ( !ms_manager )
             Init();
@@ -135,29 +145,20 @@ public:
     // called before the first wxSocket is created and should do the
     // initializations needed in order to use the network
     //
-    // return true if initialized successfully
+    // return true if initialized successfully; if this returns false sockets
+    // can't be used at all
     virtual bool OnInit() = 0;
 
     // undo the initializations of OnInit()
     virtual void OnExit() = 0;
 
 
-    // do manager-specific socket initializations: called in the beginning of
-    // the socket initialization
-    virtual bool Init_Socket(GSocket *socket) = 0;
-
-    // called when the socket is being closed
+    // create a concrete socket implementation associated with the given
+    // wxSocket object
     //
-    // TODO: merge this with Destroy_Socket(), currently 2 separate functions
-    //       are needed because Init_Socket() always allocates manager-specific
-    //       resources in GSocket and Destroy_Socket() must be called even if
-    //       the socket has never been opened, but if the allocation were done
-    //       on demand, then Destroy_Socket() could be called from
-    //       GSocket::Close() and we wouldn't need Close_Socket() at all
-    virtual void Close_Socket(GSocket *socket) = 0;
+    // the returned object must be deleted by the caller
+    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket) = 0;
 
-    // undo Init_Socket(): called from GSocket dtor
-    virtual void Destroy_Socket(GSocket *socket) = 0;
 
 
     // these functions enable or disable monitoring of the given socket for the
@@ -165,77 +166,134 @@ public:
     // that both BSD and Winsock implementations actually use socket->m_server
     // value to determine what exactly should be monitored so it needs to be
     // set before calling these functions)
-    virtual void Install_Callback(GSocket *socket,
-                                  GSocketEvent event = GSOCK_MAX_EVENT) = 0;
-    virtual void Uninstall_Callback(GSocket *socket,
-                                    GSocketEvent event = GSOCK_MAX_EVENT) = 0;
+    virtual void Install_Callback(wxSocketImpl *socket,
+                                  wxSocketNotify event = wxSOCKET_MAX_EVENT) = 0;
+    virtual void Uninstall_Callback(wxSocketImpl *socket,
+                                    wxSocketNotify event = wxSOCKET_MAX_EVENT) = 0;
 
-    virtual ~GSocketManager() { }
+    virtual ~wxSocketManager() { }
 
 private:
     // get the manager to use if we don't have it yet
     static void Init();
 
-    static GSocketManager *ms_manager;
+    static wxSocketManager *ms_manager;
 };
 
 /*
-    Base class providing functionality common to BSD and Winsock sockets.
+    Base class for all socket implementations providing functionality common to
+    BSD and Winsock sockets.
 
-    TODO: merge this in wxSocket itself, there is no reason to maintain the
-          separation between wxSocket and GSocket.
+    Objects of this class are not created directly but only via its static
+    Create() method which in turn forwards to wxSocketManager::CreateSocket().
  */
-class GSocketBase
+class wxSocketImpl
 {
 public:
     // static factory function: creates the low-level socket associated with
     // the given wxSocket (and inherits its attributes such as timeout)
-    static GSocket *Create(wxSocketBase& wxsocket);
+    static wxSocketImpl *Create(wxSocketBase& wxsocket);
 
-    virtual ~GSocketBase();
+    virtual ~wxSocketImpl();
 
+    // set various socket properties: all of those can only be called before
+    // creating the socket
     void SetTimeout(unsigned long millisec);
+    void SetNonBlocking(bool non_blocking) { m_non_blocking = non_blocking; }
+    void SetReusable() { m_reusable = true; }
+    void SetBroadcast() { m_broadcast = true; }
+    void DontDoBind() { m_dobind = false; }
+    void SetInitialSocketBuffers(int recv, int send)
+    {
+        m_initialRecvBufferSize = recv;
+        m_initialSendBufferSize = send;
+    }
+
+    wxSocketError SetLocal(GAddress *address);
+    wxSocketError SetPeer(GAddress *address);
+
+    // accessors
+    // ---------
 
-    GSocketError SetLocal(GAddress *address);
-    GSocketError SetPeer(GAddress *address);
     GAddress *GetLocal();
     GAddress *GetPeer();
 
-    GSocketEventFlags Select(GSocketEventFlags flags);
+    wxSocketError GetError() const { return m_error; }
+    bool IsOk() const { return m_error == wxSOCKET_NOERROR; }
 
-    virtual GSocket *WaitConnection(wxSocketBase& wxsocket) = 0;
 
+    // creating/closing the socket
+    // --------------------------
+
+    // notice that SetLocal() must be called before creating the socket using
+    // any of the functions below
+    //
+    // all of Create() functions return wxSOCKET_NOERROR if the operation
+    // completed successfully or one of:
+    //  wxSOCKET_INVSOCK - the socket is in use.
+    //  wxSOCKET_INVADDR - the local (server) or peer (client) address has not
+    //                     been set.
+    //  wxSOCKET_IOERR   - any other error.
+
+    // create a socket listening on the local address specified by SetLocal()
+    // (notice that DontDoBind() is ignored by this function)
+    wxSocketError CreateServer();
+
+    // create a socket connected to the peer address specified by SetPeer()
+    // (notice that DontDoBind() is ignored by this function)
+    //
+    // this function may return wxSOCKET_WOULDBLOCK in addition to the return
+    // values listed above
+    wxSocketError CreateClient();
+
+    // create (and bind unless DontDoBind() had been called) an UDP socket
+    // associated with the given local address
+    wxSocketError CreateUDP();
+
+    // may be called whether the socket was created or not, calls DoClose() if
+    // it was indeed created
     void Close();
+
     virtual void Shutdown();
 
-    void SetInitialSocketBuffers(int recv, int send)
-    {
-        m_initialRecvBufferSize = recv;
-        m_initialSendBufferSize = send;
-    }
+
+    // IO operations
+    // -------------
+
+    virtual int Read(char *buffer, int size) = 0;
+    virtual int Write(const char *buffer, int size) = 0;
+
+    wxSocketEventFlags Select(wxSocketEventFlags flags);
+
+    virtual wxSocketImpl *WaitConnection(wxSocketBase& wxsocket) = 0;
+
+
+    // notifications
+    // -------------
 
     // notify m_wxsocket about the given socket event by calling its (inaptly
     // named) OnRequest() method
-    void NotifyOnStateChange(GSocketEvent event);
+    void NotifyOnStateChange(wxSocketNotify event);
 
     // FIXME: making these functions virtual is a hack necessary to make the
     //        wxBase library link without requiring wxNet under Unix where
-    //        GSocketSelectManager (part of wxBase) uses them, they don't
+    //        wxSocketSelectManager (part of wxBase) uses them, they don't
     //        really need to be virtual at all
     virtual void Detected_Read() { }
     virtual void Detected_Write() { }
+    virtual void Notify(bool WXUNUSED(notify)) { }
 
-    // this is officially SOCKET (unsigned int) under Windows but we don't want
-    // to include winsock.h which defines SOCKET from here so just use int
-    // under all platforms
-    int m_fd;
+    // TODO: make these fields protected and provide accessors for those of
+    //       them that wxSocketBase really needs
+//protected:
+    SOCKET m_fd;
 
     int m_initialRecvBufferSize;
     int m_initialSendBufferSize;
 
     GAddress *m_local;
     GAddress *m_peer;
-    GSocketError m_error;
+    wxSocketError m_error;
 
     bool m_non_blocking;
     bool m_server;
@@ -247,37 +305,71 @@ public:
 
     struct timeval m_timeout;
 
-    GSocketEventFlags m_detected;
+    wxSocketEventFlags m_detected;
 
 protected:
-    GSocketBase(wxSocketBase& wxsocket);
+    wxSocketImpl(wxSocketBase& wxsocket);
 
 private:
+    // handle the given connect() return value (which may be 0 or EWOULDBLOCK
+    // or something else)
+    virtual wxSocketError DoHandleConnect(int ret) = 0;
+
+    // called by Close() if we have a valid m_fd
+    virtual void DoClose() = 0;
+
+    // put this socket into non-blocking mode and enable monitoring this socket
+    // as part of the event loop
+    virtual void UnblockAndRegisterWithEventLoop() = 0;
+
+    // check that the socket wasn't created yet and that the given address
+    // (either m_local or m_peer depending on the socket kind) is valid and
+    // set m_error and return false if this is not the case
+    bool PreCreateCheck(GAddress *addr);
+
+    // set the given socket option: this just wraps setsockopt(SOL_SOCKET)
+    int SetSocketOption(int optname, int optval)
+    {
+        // although modern Unix systems use "const void *" for the 4th
+        // parameter here, old systems and Winsock still use "const char *"
+        return setsockopt(m_fd, SOL_SOCKET, optname,
+                          reinterpret_cast<const char *>(&optval),
+                          sizeof(optval));
+    }
+
+    // set the given socket option to true value: this is an even simpler
+    // wrapper for setsockopt(SOL_SOCKET) for boolean options
+    int EnableSocketOption(int optname)
+    {
+        return SetSocketOption(optname, 1);
+    }
+
+    // apply the options to the (just created) socket and register it with the
+    // event loop by calling UnblockAndRegisterWithEventLoop()
+    void PostCreation();
+
+    // update local address after binding/connecting
+    wxSocketError UpdateLocalAddress();
+
+
     // set in ctor and never changed except that it's reset to NULL when the
     // socket is shut down
     wxSocketBase *m_wxsocket;
 
-    DECLARE_NO_COPY_CLASS(GSocketBase)
+    DECLARE_NO_COPY_CLASS(wxSocketImpl)
 };
 
-#if defined(__WINDOWS__)
+#if defined(__WXMSW__)
     #include "wx/msw/gsockmsw.h"
 #else
     #include "wx/unix/gsockunx.h"
 #endif
 
-/* Global initializers */
-
-/* GSocket_Init() must be called at the beginning (but after calling
- * GSocketManager::Set() if a custom manager should be used) */
-bool GSocket_Init();
-
-/* GSocket_Cleanup() must be called at the end */
-void GSocket_Cleanup();
-
 
 /* GAddress */
 
+// TODO: make GAddress a real class instead of this mix of C and C++
+
 // Represents a socket endpoint, i.e. -- in spite of its name -- not an address
 // but an (address, port) pair
 struct GAddress
@@ -288,7 +380,7 @@ struct GAddress
     GAddressType m_family;
     int m_realfamily;
 
-    GSocketError m_error;
+    wxSocketError m_error;
 };
 
 GAddress *GAddress_new();
@@ -303,48 +395,48 @@ GAddressType GAddress_GetFamily(GAddress *address);
  * address family will be implicitly set to AF_INET.
  */
 
-GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
-GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address);
-GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
-GSocketError GAddress_INET_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
+wxSocketError GAddress_INET_SetBroadcastAddress(GAddress *address);
+wxSocketError GAddress_INET_SetAnyAddress(GAddress *address);
+wxSocketError GAddress_INET_SetHostAddress(GAddress *address,
                                           unsigned long hostaddr);
-GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
                                        const char *protocol);
-GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
+wxSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
 
-GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
+wxSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
                                        size_t sbuf);
 unsigned long GAddress_INET_GetHostAddress(GAddress *address);
 unsigned short GAddress_INET_GetPort(GAddress *address);
 
-GSocketError _GAddress_translate_from(GAddress *address,
+wxSocketError _GAddress_translate_from(GAddress *address,
                                       struct sockaddr *addr, int len);
-GSocketError _GAddress_translate_to  (GAddress *address,
+wxSocketError _GAddress_translate_to  (GAddress *address,
                                       struct sockaddr **addr, int *len);
-GSocketError _GAddress_Init_INET(GAddress *address);
+wxSocketError _GAddress_Init_INET(GAddress *address);
 
 #if wxUSE_IPV6
 
-GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname);
-GSocketError GAddress_INET6_SetAnyAddress(GAddress *address);
-GSocketError GAddress_INET6_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname);
+wxSocketError GAddress_INET6_SetAnyAddress(GAddress *address);
+wxSocketError GAddress_INET6_SetHostAddress(GAddress *address,
                                           struct in6_addr hostaddr);
-GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
                                        const char *protocol);
-GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port);
+wxSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port);
 
-GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname,
+wxSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname,
                                        size_t sbuf);
-GSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr);
+wxSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr);
 unsigned short GAddress_INET6_GetPort(GAddress *address);
 
 #endif // wxUSE_IPV6
 
 // these functions are available under all platforms but only implemented under
-// Unix ones, elsewhere they just return GSOCK_INVADDR
-GSocketError _GAddress_Init_UNIX(GAddress *address);
-GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
-GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
+// Unix ones, elsewhere they just return wxSOCKET_INVADDR
+wxSocketError _GAddress_Init_UNIX(GAddress *address);
+wxSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
+wxSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
 
 #endif /* wxUSE_SOCKETS */
 
index 65f529d32752d897689e3609d3cf8301a3dd99d2..61ecbc2f7f991f33a0000f7d4757183177cc621f 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        wx/private/gsocketiohandler.h
-// Purpose:     class for registering GSocket in wxSelectDispatcher
+// Purpose:     class for registering sockets with wxSelectDispatcher
 // Authors:     Lukasz Michalski
 // Created:     December 2006
 // Copyright:   (c) Lukasz Michalski
 #include "wx/private/selectdispatcher.h"
 #include "wx/private/gsocket.h"
 
-class WXDLLIMPEXP_BASE wxGSocketIOHandler : public wxFDIOHandler
+class WXDLLIMPEXP_BASE wxSocketIOHandler : public wxFDIOHandler
 {
 public:
-    wxGSocketIOHandler(GSocket* socket)
+    wxSocketIOHandler(wxSocketImpl *socket)
     {
         m_socket = socket;
         m_flags = 0;
@@ -36,7 +36,7 @@ public:
     virtual void OnExceptionWaiting() { m_socket->Detected_Read(); }
 
 private:
-    GSocket* m_socket;
+    wxSocketImpl *m_socket;
     int m_flags;
 };
 
index 8c40673a989e5228f694995e86609aa3dc0f0499..1b72a2cd56eb22b46cd6f850f768779616a6355d 100644 (file)
 
 #include "wx/event.h"
 #include "wx/sckaddr.h"
-#include "wx/private/gsocket.h"
 #include "wx/list.h"
 
+class wxSocketImpl;
+
 // ------------------------------------------------------------------------
 // Types and constants
 // ------------------------------------------------------------------------
 
+// Types of different socket notifications or events.
+//
+// NB: the values here should be consecutive and start with 0 as they are
+//     used to construct the wxSOCKET_XXX_FLAG bit mask values below
 enum wxSocketNotify
 {
-  wxSOCKET_INPUT = GSOCK_INPUT,
-  wxSOCKET_OUTPUT = GSOCK_OUTPUT,
-  wxSOCKET_CONNECTION = GSOCK_CONNECTION,
-  wxSOCKET_LOST = GSOCK_LOST
+    wxSOCKET_INPUT,
+    wxSOCKET_OUTPUT,
+    wxSOCKET_CONNECTION,
+    wxSOCKET_LOST,
+    wxSOCKET_MAX_EVENT
 };
 
 enum
 {
-  wxSOCKET_INPUT_FLAG = GSOCK_INPUT_FLAG,
-  wxSOCKET_OUTPUT_FLAG = GSOCK_OUTPUT_FLAG,
-  wxSOCKET_CONNECTION_FLAG = GSOCK_CONNECTION_FLAG,
-  wxSOCKET_LOST_FLAG = GSOCK_LOST_FLAG
+    wxSOCKET_INPUT_FLAG = 1 << wxSOCKET_INPUT,
+    wxSOCKET_OUTPUT_FLAG = 1 << wxSOCKET_OUTPUT,
+    wxSOCKET_CONNECTION_FLAG = 1 << wxSOCKET_CONNECTION,
+    wxSOCKET_LOST_FLAG = 1 << wxSOCKET_LOST
 };
 
-typedef GSocketEventFlags wxSocketEventFlags;
+// this is a combination of the bit masks defined above
+typedef int wxSocketEventFlags;
 
 enum wxSocketError
 {
-  // from GSocket
-  wxSOCKET_NOERROR = GSOCK_NOERROR,
-  wxSOCKET_INVOP = GSOCK_INVOP,
-  wxSOCKET_IOERR = GSOCK_IOERR,
-  wxSOCKET_INVADDR = GSOCK_INVADDR,
-  wxSOCKET_INVSOCK = GSOCK_INVSOCK,
-  wxSOCKET_NOHOST = GSOCK_NOHOST,
-  wxSOCKET_INVPORT = GSOCK_INVPORT,
-  wxSOCKET_WOULDBLOCK = GSOCK_WOULDBLOCK,
-  wxSOCKET_TIMEDOUT = GSOCK_TIMEDOUT,
-  wxSOCKET_MEMERR = GSOCK_MEMERR,
-
-  // wxSocket-specific (not yet implemented)
-  wxSOCKET_DUMMY
+    wxSOCKET_NOERROR = 0,
+    wxSOCKET_INVOP,
+    wxSOCKET_IOERR,
+    wxSOCKET_INVADDR,
+    wxSOCKET_INVSOCK,
+    wxSOCKET_NOHOST,
+    wxSOCKET_INVPORT,
+    wxSOCKET_WOULDBLOCK,
+    wxSOCKET_TIMEDOUT,
+    wxSOCKET_MEMERR,
+    wxSOCKET_OPTERR
 };
 
+// socket options/flags bit masks
 enum
 {
-  wxSOCKET_NONE = 0,
-  wxSOCKET_NOWAIT = 1,
-  wxSOCKET_WAITALL = 2,
-  wxSOCKET_BLOCK = 4,
-  wxSOCKET_REUSEADDR = 8,
-  wxSOCKET_BROADCAST = 16,
-  wxSOCKET_NOBIND = 32
+    wxSOCKET_NONE = 0,
+    wxSOCKET_NOWAIT = 1,
+    wxSOCKET_WAITALL = 2,
+    wxSOCKET_BLOCK = 4,
+    wxSOCKET_REUSEADDR = 8,
+    wxSOCKET_BROADCAST = 16,
+    wxSOCKET_NOBIND = 32
 };
 
+typedef int wxSocketFlags;
+
+// socket kind values (badly defined, don't use)
 enum wxSocketType
 {
-  wxSOCKET_UNINIT,
-  wxSOCKET_CLIENT,
-  wxSOCKET_SERVER,
-  wxSOCKET_BASE,
-  wxSOCKET_DATAGRAM
+    wxSOCKET_UNINIT,
+    wxSOCKET_CLIENT,
+    wxSOCKET_SERVER,
+    wxSOCKET_BASE,
+    wxSOCKET_DATAGRAM
 };
 
-typedef int wxSocketFlags;
-
 
 
 // --------------------------------------------------------------------------
@@ -111,14 +117,14 @@ public:
 
   // state
   bool Ok() const { return IsOk(); }
-  bool IsOk() const { return (m_socket != NULL); }
+  bool IsOk() const { return m_impl != NULL; }
   bool Error() const { return m_error; }
   bool IsClosed() const { return m_closed; }
   bool IsConnected() const { return m_connected; }
   bool IsData() { return WaitForRead(0, 0); }
   bool IsDisconnected() const { return !IsConnected(); }
   wxUint32 LastCount() const { return m_lcount; }
-  wxSocketError LastError() const { return (wxSocketError)m_socket->GetError(); }
+  wxSocketError LastError() const;
   void SaveState();
   void RestoreState();
 
@@ -182,7 +188,7 @@ public:
   // Implementation from now on
   // --------------------------
 
-  // do not use, should be private (called from GSocket)
+  // do not use, should be private (called from wxSocketImpl only)
   void OnRequest(wxSocketNotify notify);
 
   // do not use, not documented nor supported
@@ -201,7 +207,7 @@ private:
   // wait until the given flags are set for this socket or the given timeout
   // (or m_timeout) expires
   //
-  // notice that GSOCK_LOST_FLAG is always taken into account but the return
+  // notice that wxSOCKET_LOST_FLAG is always taken into account but the return
   // value depends on whether it is included in flags or not: if it is, and the
   // connection is indeed lost, true is returned, but if it isn't then the
   // function returns false in this case
@@ -215,7 +221,7 @@ private:
 
 private:
   // socket
-  GSocket      *m_socket;           // GSocket
+  wxSocketImpl *m_impl;             // port-specific implementation
   wxSocketType  m_type;             // wxSocket type
 
   // state
index 79b336c7b7ea994d02241f1094753c7be71e3eb3..ca3f3744c00dcc0d7fd2d97c2c6b7d450baba867 100644 (file)
@@ -52,6 +52,4 @@ private:
     // the signal handlers
     WX_DECLARE_HASH_MAP(int, SignalHandler, wxIntegerHash, wxIntegerEqual, SignalHandlerHash);
     SignalHandlerHash m_signalHandlerHash;
-
-    friend class GSocketGUIFunctionsTableBase;
 };
index 153d65c73540fd2f4dad5fac1768c43846538dea..a91141b8600a9661fd13e37f6a033ba3da8056a7 100644 (file)
@@ -46,13 +46,13 @@ public:
     // wxThread helpers
     // ----------------
 
-    // TODO
-
-#if wxUSE_SOCKETS
+    // Darwin uses the same wxSocketManager in console and GUI and, like MSW,
+    // uses SetDefaultSocketManager() to initialize it
+#if wxUSE_SOCKETS && !defined(__DARWIN__)
     // returns the select()-based socket manager for console applications which
     // is also used by some ports (wxX11, wxDFB) in the GUI build (hence it is
     // here and not in wxConsoleAppTraits)
-    virtual GSocketManager *GetSocketManager();
+    virtual wxSocketManager *GetSocketManager();
 #endif
 
 protected:
index 0161332ce4912cc7e463a8a6d1799f1d36c34b65..d29686af5716165146e052d3e6bd6e14a16c48bb 100644 (file)
@@ -81,7 +81,7 @@ public:
 #endif
 
 #if wxUSE_SOCKETS && defined(wxHAS_GUI_SOCKET_MANAGER)
-    virtual GSocketManager *GetSocketManager();
+    virtual wxSocketManager *GetSocketManager();
 #endif
 };
 
index 9fa9e77fbf3e9f0f01a243a2e9e13f68e4fc638c..21ffe39e2b3a046ec01cc717cd6323e6dd4d8d94 100644 (file)
@@ -1,51 +1,62 @@
-/* -------------------------------------------------------------------------
- * Project:     GSocket (Generic Socket) for WX
- * Name:        gsockunx.h
- * Copyright:   (c) Guilhem Lavaux
- * Licence:     wxWindows Licence
- * Purpose:     GSocket Unix header
- * CVSID:       $Id$
- * -------------------------------------------------------------------------
- */
+/////////////////////////////////////////////////////////////////////////////
+// Name:        wx/unix/gsockunx.h
+// Purpose:     wxSocketImpl implementation for Unix systems
+// Authors:     Guilhem Lavaux, Vadim Zeitlin
+// Created:     April 1997
+// RCS-ID:      $Id$
+// Copyright:   (c) 1997 Guilhem Lavaux
+//              (c) 2008 Vadim Zeitlin
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
 
 #ifndef _WX_UNIX_GSOCKUNX_H_
 #define _WX_UNIX_GSOCKUNX_H_
 
 #include <unistd.h>
+#include <sys/ioctl.h>
 
-class wxGSocketIOHandler;
+class wxSocketIOHandler;
 
-class GSocket : public GSocketBase
+class wxSocketImplUnix : public wxSocketImpl
 {
 public:
-    GSocket(wxSocketBase& wxsocket);
-    virtual ~GSocket();
+    wxSocketImplUnix(wxSocketBase& wxsocket);
 
     virtual void Shutdown();
-    virtual GSocket *WaitConnection(wxSocketBase& wxsocket);
-
-    GSocketError SetServer();
-    bool SetReusable();
-    bool SetBroadcast();
-    bool DontDoBind();
-    GSocketError Connect(GSocketStream stream);
-    GSocketError SetNonOriented();
+    virtual wxSocketImpl *WaitConnection(wxSocketBase& wxsocket);
+
     int Read(char *buffer, int size);
     int Write(const char *buffer, int size);
-    void SetNonBlocking(bool non_block);
-    GSocketError WXDLLIMPEXP_NET GetError();
-    GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
-    GSocketError SetSockOpt(int level, int optname,
-        const void *optval, int optlen);
     //attach or detach from main loop
     void Notify(bool flag);
     void Detected_Read();
     void Detected_Write();
 
 private:
+    virtual wxSocketError DoHandleConnect(int ret);
+    virtual void DoClose()
+    {
+        wxSocketManager * const manager = wxSocketManager::Get();
+        if ( manager )
+        {
+            manager->Uninstall_Callback(this, wxSOCKET_INPUT);
+            manager->Uninstall_Callback(this, wxSOCKET_OUTPUT);
+        }
+
+        close(m_fd);
+    }
+
+    virtual void UnblockAndRegisterWithEventLoop()
+    {
+        int trueArg = 1;
+        ioctl(m_fd, FIONBIO, &trueArg);
+
+        EnableEvents();
+    }
+
     // enable or disable notifications for socket input/output events but only
     // if m_use_events is true; do nothing otherwise
-    void EnableEvents()
+    virtual void EnableEvents()
     {
         if ( m_use_events )
             DoEnableEvents(true);
@@ -67,38 +78,36 @@ private:
     //
     // notice that these functions also update m_detected: EnableEvent() clears
     // the corresponding bit in it and DisableEvent() sets it
-    void EnableEvent(GSocketEvent event);
-    void DisableEvent(GSocketEvent event);
+    void EnableEvent(wxSocketNotify event);
+    void DisableEvent(wxSocketNotify event);
 
 
-    GSocketError Input_Timeout();
-    GSocketError Output_Timeout();
+    wxSocketError Input_Timeout();
+    wxSocketError Output_Timeout();
     int Recv_Stream(char *buffer, int size);
     int Recv_Dgram(char *buffer, int size);
     int Send_Stream(const char *buffer, int size);
     int Send_Dgram(const char *buffer, int size);
-public:
-    /* DFE: We can't protect these data member until the GUI code is updated */
-    /* protected: */
-  wxGSocketIOHandler *m_handler;
 
-  // true if socket should fire events
-  bool m_use_events;
+protected:
+    // true if socket should fire events
+    bool m_use_events;
 
-  // pointer for storing extra (usually GUI-specific) data
-  void *m_gui_dependent;
+    // descriptors for input and output event notification channels associated
+    // with the socket
+    int m_fds[2];
 
 private:
     // notify the associated wxSocket about a change in socket state and shut
-    // down the socket if the event is GSOCK_LOST
-    void OnStateChange(GSocketEvent event);
+    // down the socket if the event is wxSOCKET_LOST
+    void OnStateChange(wxSocketNotify event);
+
+    // give it access to our m_fds
+    friend class wxSocketFDBasedManager;
 };
 
-// A version of GSocketManager which uses FDs for socket IO
-//
-// This class uses GSocket::m_gui_dependent field to store the 2 (for input and
-// output) FDs associated with the socket.
-class GSocketFDBasedManager : public GSocketManager
+// A version of wxSocketManager which uses FDs for socket IO
+class wxSocketFDBasedManager : public wxSocketManager
 {
 public:
     // no special initialization/cleanup needed when using FDs
@@ -106,28 +115,9 @@ public:
     virtual void OnExit() { }
 
     // allocate/free the storage we need
-    virtual bool Init_Socket(GSocket *socket)
-    {
-        socket->m_gui_dependent = malloc(sizeof(int)*2);
-        int * const fds = static_cast<int *>(socket->m_gui_dependent);
-
-        fds[0] = -1;
-        fds[1] = -1;
-
-        return true;
-    }
-
-    virtual void Close_Socket(GSocket *socket)
-    {
-        Uninstall_Callback(socket, GSOCK_INPUT);
-        Uninstall_Callback(socket, GSOCK_OUTPUT);
-
-        close(socket->m_fd);
-    }
-
-    virtual void Destroy_Socket(GSocket *socket)
+    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
     {
-        free(socket->m_gui_dependent);
+        return new wxSocketImplUnix(wxsocket);
     }
 
 protected:
@@ -140,8 +130,8 @@ protected:
         FD_OUTPUT
     };
 
-    // get the FD index corresponding to the given GSocketEvent
-    SocketDir GetDirForEvent(GSocket *socket, GSocketEvent event)
+    // get the FD index corresponding to the given wxSocketNotify
+    SocketDir GetDirForEvent(wxSocketImpl *socket, wxSocketNotify event)
     {
         switch ( event )
         {
@@ -149,34 +139,34 @@ protected:
                 wxFAIL_MSG( "unexpected socket event" );
                 // fall through
 
-            case GSOCK_LOST:
+            case wxSOCKET_LOST:
                 // fall through
 
-            case GSOCK_INPUT:
+            case wxSOCKET_INPUT:
                 return FD_INPUT;
 
-            case GSOCK_OUTPUT:
+            case wxSOCKET_OUTPUT:
                 return FD_OUTPUT;
 
-            case GSOCK_CONNECTION:
+            case wxSOCKET_CONNECTION:
                 // FIXME: explain this?
                 return socket->m_server ? FD_INPUT : FD_OUTPUT;
         }
     }
 
     // access the FDs we store
-    int& FD(GSocket *socket, SocketDir d)
+    int& FD(wxSocketImpl *socket, SocketDir d)
     {
-        return static_cast<int *>(socket->m_gui_dependent)[d];
+        return static_cast<wxSocketImplUnix *>(socket)->m_fds[d];
     }
 };
 
 // Common base class for all ports using X11-like (and hence implemented in
 // X11, Motif and GTK) AddInput() and RemoveInput() functions
-class GSocketInputBasedManager : public GSocketFDBasedManager
+class wxSocketInputBasedManager : public wxSocketFDBasedManager
 {
 public:
-    virtual void Install_Callback(GSocket *socket, GSocketEvent event)
+    virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event)
     {
         wxCHECK_RET( socket->m_fd != -1,
                         "shouldn't be called on invalid socket" );
@@ -190,7 +180,7 @@ public:
         fd = AddInput(socket, d);
     }
 
-    virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event)
+    virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event)
     {
         const SocketDir d = GetDirForEvent(socket, event);
 
@@ -205,7 +195,7 @@ public:
 private:
     // these functions map directly to XtAdd/RemoveInput() or
     // gdk_input_add/remove()
-    virtual int AddInput(GSocket *socket, SocketDir d) = 0;
+    virtual int AddInput(wxSocketImpl *socket, SocketDir d) = 0;
     virtual void RemoveInput(int fd) = 0;
 };
 
index 7b2636e47cc930e58c1f15a4ef68c9cb3e637ff7..5a741b70ac439b3c2148aafe03a821f4aa963536 100644 (file)
@@ -111,6 +111,8 @@ wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL;
 
 wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL;
 
+wxSocketManager *wxAppTraitsBase::ms_manager = NULL;
+
 // ----------------------------------------------------------------------------
 // wxEventLoopPtr
 // ----------------------------------------------------------------------------
index f31a6ecf990e25155942bdbb39ddcf9909499ce6..f0ea86537ec0a8a5edca630d74906ab133b2238c 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // Name:        src/common/gsocketiohandler.cpp
-// Purpose:     implementation of wxFDIOHandler for GSocket
+// Purpose:     implementation of wxFDIOHandler for wxSocket
 // Author:      Angel Vidal, Lukasz Michalski
 // Created:     08.24.06
 // RCS-ID:      $Id$
 // ============================================================================
 
 // ----------------------------------------------------------------------------
-// GSocketSelectManager
+// wxSocketImplFDIO
 // ----------------------------------------------------------------------------
 
-class GSocketSelectManager : public GSocketFDBasedManager
+class wxSocketImplFDIO : public wxSocketImplUnix
 {
 public:
-    virtual void Install_Callback(GSocket *socket, GSocketEvent event);
-    virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
+    wxSocketImplFDIO(wxSocketBase& wxsocket)
+        : wxSocketImplUnix(wxsocket)
+    {
+        m_handler = NULL;
+    }
+
+    virtual ~wxSocketImplFDIO()
+    {
+        delete m_handler;
+    }
+
+    wxSocketIOHandler *m_handler;
+};
+
+// ----------------------------------------------------------------------------
+// wxSocketSelectManager
+// ----------------------------------------------------------------------------
+
+class wxSocketSelectManager : public wxSocketFDBasedManager
+{
+public:
+    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
+    {
+        return new wxSocketImplFDIO(wxsocket);
+    }
+
+    virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
+    virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
 };
 
-void GSocketSelectManager::Install_Callback(GSocket *socket,
-                                            GSocketEvent event)
+void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_,
+                                             wxSocketNotify event)
 {
+    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+
     const int fd = socket->m_fd;
 
     if ( fd == -1 )
@@ -55,7 +83,7 @@ void GSocketSelectManager::Install_Callback(GSocket *socket,
     if ( !dispatcher )
         return;
 
-    wxGSocketIOHandler *& handler = socket->m_handler;
+    wxSocketIOHandler *& handler = socket->m_handler;
 
     // we should register the new handlers but modify the existing ones in place
     bool registerHandler;
@@ -66,7 +94,7 @@ void GSocketSelectManager::Install_Callback(GSocket *socket,
     else // no existing handler
     {
         registerHandler = true;
-        handler = new wxGSocketIOHandler(socket);
+        handler = new wxSocketIOHandler(socket);
     }
 
     FD(socket, d) = fd;
@@ -85,9 +113,11 @@ void GSocketSelectManager::Install_Callback(GSocket *socket,
         dispatcher->ModifyFD(fd, handler, handler->GetFlags());
 }
 
-void GSocketSelectManager::Uninstall_Callback(GSocket *socket,
-                                              GSocketEvent event)
+void wxSocketSelectManager::Uninstall_Callback(wxSocketImpl *socket_,
+                                               wxSocketNotify event)
 {
+    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+
     const SocketDir d = GetDirForEvent(socket, event);
 
     const int fd = FD(socket, d);
@@ -103,7 +133,7 @@ void GSocketSelectManager::Uninstall_Callback(GSocket *socket,
     if ( !dispatcher )
         return;
 
-    wxGSocketIOHandler *& handler = socket->m_handler;
+    wxSocketIOHandler *& handler = socket->m_handler;
     if ( handler )
     {
         handler->RemoveFlag(flag);
@@ -125,9 +155,9 @@ void GSocketSelectManager::Uninstall_Callback(GSocket *socket,
     }
 }
 
-GSocketManager *wxAppTraits::GetSocketManager()
+wxSocketManager *wxAppTraits::GetSocketManager()
 {
-    static GSocketSelectManager s_manager;
+    static wxSocketSelectManager s_manager;
 
     return &s_manager;
 }
index 9c37cc6489b3d6866f86d9ebe1d48a4aee72e65b..aee1b58cbf07e574a257a93341009c9594451941 100644 (file)
@@ -145,12 +145,12 @@ bool wxIPV4address::Hostname(const wxString& name)
     return false;
   }
   m_origHostname = name;
-  return (GAddress_INET_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR);
+  return (GAddress_INET_SetHostName(m_address, name.mb_str()) == wxSOCKET_NOERROR);
 }
 
 bool wxIPV4address::Hostname(unsigned long addr)
 {
-  bool rv = (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR);
+  bool rv = (GAddress_INET_SetHostAddress(m_address, addr) == wxSOCKET_NOERROR);
   if (rv)
       m_origHostname = Hostname();
   else
@@ -160,17 +160,17 @@ bool wxIPV4address::Hostname(unsigned long addr)
 
 bool wxIPV4address::Service(const wxString& name)
 {
-  return (GAddress_INET_SetPortName(m_address, name.mb_str(), "tcp") == GSOCK_NOERROR);
+  return (GAddress_INET_SetPortName(m_address, name.mb_str(), "tcp") == wxSOCKET_NOERROR);
 }
 
 bool wxIPV4address::Service(unsigned short port)
 {
-  return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
+  return (GAddress_INET_SetPort(m_address, port) == wxSOCKET_NOERROR);
 }
 
 bool wxIPV4address::LocalHost()
 {
-  return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
+  return (GAddress_INET_SetHostName(m_address, "localhost") == wxSOCKET_NOERROR);
 }
 
 bool wxIPV4address::IsLocalHost() const
@@ -180,12 +180,12 @@ bool wxIPV4address::IsLocalHost() const
 
 bool wxIPV4address::BroadcastAddress()
 {
-  return (GAddress_INET_SetBroadcastAddress(m_address) == GSOCK_NOERROR);
+  return (GAddress_INET_SetBroadcastAddress(m_address) == wxSOCKET_NOERROR);
 }
 
 bool wxIPV4address::AnyAddress()
 {
-  return (GAddress_INET_SetAnyAddress(m_address) == GSOCK_NOERROR);
+  return (GAddress_INET_SetAnyAddress(m_address) == wxSOCKET_NOERROR);
 }
 
 wxString wxIPV4address::Hostname() const
@@ -253,7 +253,7 @@ bool wxIPV6address::Hostname(const wxString& name)
     return false;
   }
   m_origHostname = name;
-  return (GAddress_INET6_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR);
+  return (GAddress_INET6_SetHostName(m_address, name.mb_str()) == wxSOCKET_NOERROR);
 }
 
 bool wxIPV6address::Hostname(unsigned char addr[16])
@@ -273,17 +273,17 @@ bool wxIPV6address::Hostname(unsigned char addr[16])
 
 bool wxIPV6address::Service(const wxString& name)
 {
-  return (GAddress_INET6_SetPortName(m_address, name.mb_str(), "tcp") == GSOCK_NOERROR);
+  return (GAddress_INET6_SetPortName(m_address, name.mb_str(), "tcp") == wxSOCKET_NOERROR);
 }
 
 bool wxIPV6address::Service(unsigned short port)
 {
-  return (GAddress_INET6_SetPort(m_address, port) == GSOCK_NOERROR);
+  return (GAddress_INET6_SetPort(m_address, port) == wxSOCKET_NOERROR);
 }
 
 bool wxIPV6address::LocalHost()
 {
-  return (GAddress_INET6_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
+  return (GAddress_INET6_SetHostName(m_address, "localhost") == wxSOCKET_NOERROR);
 }
 
 bool wxIPV6address::IsLocalHost() const
@@ -306,7 +306,7 @@ bool wxIPV6address::BroadcastAddress()
 
 bool wxIPV6address::AnyAddress()
 {
-  return (GAddress_INET6_SetAnyAddress(m_address) == GSOCK_NOERROR);
+  return (GAddress_INET6_SetAnyAddress(m_address) == wxSOCKET_NOERROR);
 }
 
 wxString wxIPV6address::IPAddress() const
@@ -356,7 +356,7 @@ wxString wxIPV6address::Hostname() const
 
    if ( GAddress_INET6_GetHostName(m_address,
                                    hostname,
-                                   WXSIZEOF(hostname)) != GSOCK_NOERROR )
+                                   WXSIZEOF(hostname)) != wxSOCKET_NOERROR )
        return wxEmptyString;
 
    return wxString::FromAscii(hostname);
index 2487fddcfb76b08aa7408bf97d807a8975cd4609..a4fb0d8f73f1468abc16d40a1f5d5e4449da8322 100644 (file)
@@ -4,7 +4,8 @@
 // Authors:    Guilhem Lavaux, Guillermo Rodriguez Garcia
 // Created:    April 1997
 // Copyright:  (C) 1999-1997, Guilhem Lavaux
-//             (C) 2000-1999, Guillermo Rodriguez Garcia
+//             (C) 1999-2000, Guillermo Rodriguez Garcia
+//             (C) 2008 Vadim Zeitlin
 // RCS_ID:     $Id$
 // License:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -43,7 +44,7 @@
 #include "wx/evtloop.h"
 
 #include "wx/private/fd.h"
-#include "wx/private/socket.h"
+#include "wx/private/gsocket.h"
 
 // DLL options compatibility check:
 #include "wx/build.h"
@@ -90,35 +91,35 @@ public:
 class wxSocketUnblocker
 {
 public:
-    wxSocketUnblocker(GSocket *socket, bool unblock = true)
-        : m_socket(socket),
+    wxSocketUnblocker(wxSocketImpl *socket, bool unblock = true)
+        : m_impl(socket),
           m_unblock(unblock)
     {
         if ( m_unblock )
-            m_socket->SetNonBlocking(true);
+            m_impl->SetNonBlocking(true);
     }
 
     ~wxSocketUnblocker()
     {
         if ( m_unblock )
-            m_socket->SetNonBlocking(false);
+            m_impl->SetNonBlocking(false);
     }
 
 private:
-    GSocket * const m_socket;
+    wxSocketImpl * const m_impl;
     bool m_unblock;
 
     DECLARE_NO_COPY_CLASS(wxSocketUnblocker)
 };
 
 // ============================================================================
-// GSocketManager
+// wxSocketManager
 // ============================================================================
 
-GSocketManager *GSocketManager::ms_manager = NULL;
+wxSocketManager *wxSocketManager::ms_manager = NULL;
 
 /* static */
-void GSocketManager::Set(GSocketManager *manager)
+void wxSocketManager::Set(wxSocketManager *manager)
 {
     wxASSERT_MSG( !ms_manager, "too late to set manager now" );
 
@@ -126,7 +127,7 @@ void GSocketManager::Set(GSocketManager *manager)
 }
 
 /* static */
-void GSocketManager::Init()
+void wxSocketManager::Init()
 {
     wxASSERT_MSG( !ms_manager, "shouldn't be initialized twice" );
 
@@ -156,30 +157,24 @@ void GSocketManager::Init()
 }
 
 // ==========================================================================
-// GSocketBase
+// wxSocketImpl
 // ==========================================================================
 
 /* static */
-GSocket *GSocketBase::Create(wxSocketBase& wxsocket)
+wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
 {
-    GSocket * const newsocket = new GSocket(wxsocket);
-    if ( !GSocketManager::Get()->Init_Socket(newsocket) )
-    {
-        delete newsocket;
-        return NULL;
-    }
-
-    return newsocket;
+    wxSocketManager * const manager = wxSocketManager::Get();
+    return manager ? manager->CreateSocket(wxsocket) : NULL;
 }
 
-GSocketBase::GSocketBase(wxSocketBase& wxsocket)
+wxSocketImpl::wxSocketImpl(wxSocketBase& wxsocket)
     : m_wxsocket(&wxsocket)
 {
     m_fd              = INVALID_SOCKET;
     m_detected        = 0;
     m_local           = NULL;
     m_peer            = NULL;
-    m_error           = GSOCK_NOERROR;
+    m_error           = wxSOCKET_NOERROR;
     m_server          = false;
     m_stream          = true;
     m_non_blocking    = false;
@@ -194,7 +189,7 @@ GSocketBase::GSocketBase(wxSocketBase& wxsocket)
     m_initialSendBufferSize = -1;
 }
 
-GSocketBase::~GSocketBase()
+wxSocketImpl::~wxSocketImpl()
 {
     if (m_fd != INVALID_SOCKET)
         Shutdown();
@@ -204,26 +199,188 @@ GSocketBase::~GSocketBase()
 
     if (m_peer)
         GAddress_destroy(m_peer);
+}
+
+bool wxSocketImpl::PreCreateCheck(GAddress *addr)
+{
+    if ( m_fd != INVALID_SOCKET )
+    {
+        m_error = wxSOCKET_INVSOCK;
+        return false;
+    }
+
+    if ( !addr || !addr->m_addr )
+    {
+        m_error = wxSOCKET_INVADDR;
+        return false;
+    }
+
+    return true;
+}
+
+void wxSocketImpl::PostCreation()
+{
+    // FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option
+#ifdef SO_NOSIGPIPE
+    EnableSocketOption(SO_NOSIGPIPE);
+#endif
+
+    if ( m_reusable )
+        EnableSocketOption(SO_REUSEADDR);
+
+    if ( m_broadcast )
+    {
+        wxASSERT_MSG( !m_stream, "broadcasting is for datagram sockets only" );
+
+        EnableSocketOption(SO_BROADCAST);
+    }
+
+    if ( m_initialRecvBufferSize >= 0 )
+        SetSocketOption(SO_RCVBUF, m_initialRecvBufferSize);
+    if ( m_initialSendBufferSize >= 0 )
+        SetSocketOption(SO_SNDBUF, m_initialSendBufferSize);
 
-    // cast is ok as all GSocketBase objects we have in our code are really
-    // GSockets
-    GSocketManager::Get()->Destroy_Socket(static_cast<GSocket *>(this));
+    // FIXME: shouldn't we check for m_non_blocking here? as it is now, all our
+    //        sockets are non-blocking
+    UnblockAndRegisterWithEventLoop();
 }
 
-void GSocketBase::Close()
+wxSocketError wxSocketImpl::UpdateLocalAddress()
+{
+    WX_SOCKLEN_T lenAddr;
+    if ( getsockname(m_fd, m_local->m_addr, &lenAddr) != 0 )
+    {
+        Close();
+        m_error = wxSOCKET_IOERR;
+        return m_error;
+    }
+
+    m_local->m_len = lenAddr;
+
+    return wxSOCKET_NOERROR;
+}
+
+wxSocketError wxSocketImpl::CreateServer()
+{
+    if ( !PreCreateCheck(m_local) )
+        return m_error;
+
+    m_server = true;
+    m_stream = true;
+
+    // do create the socket
+    m_fd = socket(m_local->m_realfamily, SOCK_STREAM, 0);
+
+    if ( m_fd == INVALID_SOCKET )
+    {
+        m_error = wxSOCKET_IOERR;
+        return wxSOCKET_IOERR;
+    }
+
+    PostCreation();
+
+    // and then bind to and listen on it
+    //
+    // FIXME: should we test for m_dobind here?
+    if ( bind(m_fd, m_local->m_addr, m_local->m_len) != 0 )
+        m_error = wxSOCKET_IOERR;
+
+    if ( IsOk() )
+    {
+        if ( listen(m_fd, 5) != 0 )
+            m_error = wxSOCKET_IOERR;
+    }
+
+    if ( !IsOk() )
+    {
+        Close();
+        return m_error;
+    }
+
+    // finally retrieve the address we effectively bound to
+    return UpdateLocalAddress();
+}
+
+wxSocketError wxSocketImpl::CreateClient()
+{
+    if ( !PreCreateCheck(m_peer) )
+        return m_error;
+
+    m_fd = socket(m_peer->m_realfamily, SOCK_STREAM, 0);
+
+    if ( m_fd == INVALID_SOCKET )
+    {
+      m_error = wxSOCKET_IOERR;
+      return wxSOCKET_IOERR;
+    }
+
+    PostCreation();
+
+    // If a local address has been set, then bind to it before calling connect
+    if ( m_local && m_local->m_addr )
+    {
+        if ( bind(m_fd, m_local->m_addr, m_local->m_len) != 0 )
+        {
+            Close();
+            m_error = wxSOCKET_IOERR;
+            return m_error;
+        }
+    }
+
+    // Connect to the peer and handle the EWOULDBLOCK return value in
+    // platform-specific code
+    return DoHandleConnect(connect(m_fd, m_peer->m_addr, m_peer->m_len));
+}
+
+
+wxSocketError wxSocketImpl::CreateUDP()
+{
+    if ( !PreCreateCheck(m_local) )
+        return m_error;
+
+    m_stream = false;
+    m_server = false;
+
+    m_fd = socket(m_local->m_realfamily, SOCK_DGRAM, 0);
+
+    if ( m_fd == INVALID_SOCKET )
+    {
+        m_error = wxSOCKET_IOERR;
+        return wxSOCKET_IOERR;
+    }
+
+    PostCreation();
+
+    if ( m_dobind )
+    {
+        if ( bind(m_fd, m_local->m_addr, m_local->m_len) != 0 )
+        {
+            Close();
+            m_error = wxSOCKET_IOERR;
+            return m_error;
+        }
+
+        return UpdateLocalAddress();
+    }
+
+    return wxSOCKET_NOERROR;
+}
+
+
+void wxSocketImpl::Close()
 {
     if ( m_fd != INVALID_SOCKET )
     {
-        GSocketManager::Get()->Close_Socket(static_cast<GSocket *>(this));
+        DoClose();
         m_fd = INVALID_SOCKET;
     }
 }
 
-/* GSocket_Shutdown:
+/*
  *  Disallow further read/write operations on this socket, close
  *  the fd and disable all callbacks.
  */
-void GSocketBase::Shutdown()
+void wxSocketImpl::Shutdown()
 {
     if ( m_fd != INVALID_SOCKET )
     {
@@ -231,56 +388,51 @@ void GSocketBase::Shutdown()
         Close();
     }
 
-    m_detected = GSOCK_LOST_FLAG;
+    m_detected = wxSOCKET_LOST_FLAG;
 }
 
-/* GSocket_SetTimeout:
+/*
  *  Sets the timeout for blocking calls. Time is expressed in
  *  milliseconds.
  */
-void GSocketBase::SetTimeout(unsigned long millis)
+void wxSocketImpl::SetTimeout(unsigned long millis)
 {
     m_timeout.tv_sec  = (millis / 1000);
     m_timeout.tv_usec = (millis % 1000) * 1000;
 }
 
-void GSocketBase::NotifyOnStateChange(GSocketEvent event)
+void wxSocketImpl::NotifyOnStateChange(wxSocketNotify event)
 {
-    // GSocketEvent and wxSocketNotify enums have the same elements with the
-    // same values
-    m_wxsocket->OnRequest(static_cast<wxSocketNotify>(event));
+    m_wxsocket->OnRequest(event);
 }
 
 /* Address handling */
 
-/* GSocket_SetLocal:
- * GSocket_GetLocal:
- * GSocket_SetPeer:
- * GSocket_GetPeer:
+/*
  *  Set or get the local or peer address for this socket. The 'set'
- *  functions return GSOCK_NOERROR on success, an error code otherwise.
+ *  functions return wxSOCKET_NOERROR on success, an error code otherwise.
  *  The 'get' functions return a pointer to a GAddress object on success,
  *  or NULL otherwise, in which case they set the error code of the
- *  corresponding GSocket.
+ *  corresponding socket.
  *
  *  Error codes:
- *    GSOCK_INVSOCK - the socket is not valid.
- *    GSOCK_INVADDR - the address is not valid.
+ *    wxSOCKET_INVSOCK - the socket is not valid.
+ *    wxSOCKET_INVADDR - the address is not valid.
  */
-GSocketError GSocketBase::SetLocal(GAddress *address)
+wxSocketError wxSocketImpl::SetLocal(GAddress *address)
 {
   /* the socket must be initialized, or it must be a server */
   if (m_fd != INVALID_SOCKET && !m_server)
   {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
+    return wxSOCKET_INVSOCK;
   }
 
   /* check address */
-  if (address == NULL || address->m_family == GSOCK_NOFAMILY)
+  if (address == NULL || address->m_family == wxSOCKET_NOFAMILY)
   {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
+    m_error = wxSOCKET_INVADDR;
+    return wxSOCKET_INVADDR;
   }
 
   if (m_local)
@@ -288,16 +440,16 @@ GSocketError GSocketBase::SetLocal(GAddress *address)
 
   m_local = GAddress_copy(address);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GSocketBase::SetPeer(GAddress *address)
+wxSocketError wxSocketImpl::SetPeer(GAddress *address)
 {
   /* check address */
-  if (address == NULL || address->m_family == GSOCK_NOFAMILY)
+  if (address == NULL || address->m_family == wxSOCKET_NOFAMILY)
   {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
+    m_error = wxSOCKET_INVADDR;
+    return wxSOCKET_INVADDR;
   }
 
   if (m_peer)
@@ -305,15 +457,15 @@ GSocketError GSocketBase::SetPeer(GAddress *address)
 
   m_peer = GAddress_copy(address);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GAddress *GSocketBase::GetLocal()
+GAddress *wxSocketImpl::GetLocal()
 {
   GAddress *address;
   wxSockAddr addr;
   WX_SOCKLEN_T size = sizeof(addr);
-  GSocketError err;
+  wxSocketError err;
 
   /* try to get it from the m_local var first */
   if (m_local)
@@ -322,24 +474,24 @@ GAddress *GSocketBase::GetLocal()
   /* else, if the socket is initialized, try getsockname */
   if (m_fd == INVALID_SOCKET)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return NULL;
   }
 
   if (getsockname(m_fd, (sockaddr*)&addr, &size) == SOCKET_ERROR)
   {
-    m_error = GSOCK_IOERR;
+    m_error = wxSOCKET_IOERR;
     return NULL;
   }
 
   /* got a valid address from getsockname, create a GAddress object */
   if ((address = GAddress_new()) == NULL)
   {
-     m_error = GSOCK_MEMERR;
+     m_error = wxSOCKET_MEMERR;
      return NULL;
   }
 
-  if ((err = _GAddress_translate_from(address, (sockaddr*)&addr, size)) != GSOCK_NOERROR)
+  if ((err = _GAddress_translate_from(address, (sockaddr*)&addr, size)) != wxSOCKET_NOERROR)
   {
      GAddress_destroy(address);
      m_error = err;
@@ -349,7 +501,7 @@ GAddress *GSocketBase::GetLocal()
   return address;
 }
 
-GAddress *GSocketBase::GetPeer()
+GAddress *wxSocketImpl::GetPeer()
 {
   /* try to get it from the m_peer var */
   if (m_peer)
@@ -379,7 +531,8 @@ bool wxSocketBase::Initialize()
 {
     if ( !m_countInit++ )
     {
-        if ( !GSocket_Init() )
+        wxSocketManager * const manager = wxSocketManager::Get();
+        if ( !manager || !manager->OnInit() )
         {
             m_countInit--;
 
@@ -396,7 +549,10 @@ void wxSocketBase::Shutdown()
     wxASSERT_MSG( m_countInit > 0, _T("extra call to Shutdown()") );
     if ( --m_countInit == 0 )
     {
-        GSocket_Cleanup();
+        wxSocketManager * const manager = wxSocketManager::Get();
+        wxCHECK_RET( manager, "should have a socket manager" );
+
+        manager->OnExit();
     }
 }
 
@@ -406,7 +562,7 @@ void wxSocketBase::Shutdown()
 
 void wxSocketBase::Init()
 {
-    m_socket       = NULL;
+    m_impl       = NULL;
     m_type         = wxSOCKET_UNINIT;
 
     // state
@@ -467,9 +623,8 @@ wxSocketBase::~wxSocketBase()
     if (!m_beingDeleted)
         Close();
 
-    // Destroy the GSocket object
-    if (m_socket)
-        delete m_socket;
+    // Destroy the implementation object
+    delete m_impl;
 
     // Free the pushback buffer
     if (m_unread)
@@ -505,6 +660,15 @@ bool wxSocketBase::Destroy()
     return true;
 }
 
+// ----------------------------------------------------------------------------
+// simply accessors
+// ----------------------------------------------------------------------------
+
+wxSocketError wxSocketBase::LastError() const
+{
+    return m_impl->GetError();
+}
+
 // --------------------------------------------------------------------------
 // Basic IO calls
 // --------------------------------------------------------------------------
@@ -519,8 +683,8 @@ bool wxSocketBase::Close()
     // Interrupt pending waits
     InterruptWait();
 
-    if (m_socket)
-        m_socket->Shutdown();
+    if (m_impl)
+        m_impl->Shutdown();
 
     m_connected = false;
     m_establishing = false;
@@ -559,7 +723,7 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
     buffer += total;
 
     // If it's indeed closed or if read everything, there is nothing more to do.
-    if ( !m_socket || !nbytes )
+    if ( !m_impl || !nbytes )
         return total;
 
     wxCHECK_MSG( buffer, 0, "NULL buffer" );
@@ -569,8 +733,8 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
     // polling the socket and don't block at all.
     if ( m_flags & wxSOCKET_NOWAIT )
     {
-        wxSocketUnblocker unblock(m_socket);
-        int ret = m_socket->Read(buffer, nbytes);
+        wxSocketUnblocker unblock(m_impl);
+        int ret = m_impl->Read(buffer, nbytes);
         if ( ret < 0 )
             return 0;
 
@@ -586,7 +750,7 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
             if ( !(m_flags & wxSOCKET_BLOCK) && !WaitForRead() )
                 break;
 
-            const int ret = m_socket->Read(buffer, nbytes);
+            const int ret = m_impl->Read(buffer, nbytes);
             if ( ret == 0 )
             {
                 // for connection-oriented (e.g. TCP) sockets we can only read
@@ -769,7 +933,7 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
     const char *buffer = static_cast<const char *>(buffer_);
 
     // Return if there is nothing to read or the socket is (already?) closed.
-    if ( !m_socket || !nbytes )
+    if ( !m_impl || !nbytes )
         return 0;
 
     wxCHECK_MSG( buffer, 0, "NULL buffer" );
@@ -777,8 +941,8 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
     wxUint32 total = 0;
     if ( m_flags & wxSOCKET_NOWAIT )
     {
-        wxSocketUnblocker unblock(m_socket);
-        const int ret = m_socket->Write(buffer, nbytes);
+        wxSocketUnblocker unblock(m_impl);
+        const int ret = m_impl->Write(buffer, nbytes);
         if ( ret > 0 )
             total += ret;
     }
@@ -789,7 +953,7 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
             if ( !(m_flags & wxSOCKET_BLOCK) && !WaitForWrite() )
                 break;
 
-            const int ret = m_socket->Write(buffer, nbytes);
+            const int ret = m_impl->Write(buffer, nbytes);
             if ( ret == 0 )
             {
                 m_closed = true;
@@ -915,25 +1079,25 @@ wxSocketBase& wxSocketBase::Discard()
 // Wait functions
 // --------------------------------------------------------------------------
 
-/* GSocket_Select:
+/*
  *  Polls the socket to determine its status. This function will
  *  check for the events specified in the 'flags' parameter, and
  *  it will return a mask indicating which operations can be
  *  performed. This function won't block, regardless of the
  *  mode (blocking | nonblocking) of the socket.
  */
-GSocketEventFlags GSocketBase::Select(GSocketEventFlags flags)
+wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags)
 {
   assert(this);
 
-  GSocketEventFlags result = 0;
+  wxSocketEventFlags result = 0;
   fd_set readfds;
   fd_set writefds;
   fd_set exceptfds;
   struct timeval tv;
 
   if (m_fd == -1)
-    return (GSOCK_LOST_FLAG & flags);
+    return (wxSOCKET_LOST_FLAG & flags);
 
   /* Do not use a static struct, Linux can garble it */
   tv.tv_sec = 0;
@@ -943,20 +1107,20 @@ GSocketEventFlags GSocketBase::Select(GSocketEventFlags flags)
   wxFD_ZERO(&writefds);
   wxFD_ZERO(&exceptfds);
   wxFD_SET(m_fd, &readfds);
-  if (flags & GSOCK_OUTPUT_FLAG || flags & GSOCK_CONNECTION_FLAG)
+  if (flags & wxSOCKET_OUTPUT_FLAG || flags & wxSOCKET_CONNECTION_FLAG)
     wxFD_SET(m_fd, &writefds);
   wxFD_SET(m_fd, &exceptfds);
 
   /* Check 'sticky' CONNECTION flag first */
-  result |= GSOCK_CONNECTION_FLAG & m_detected;
+  result |= wxSOCKET_CONNECTION_FLAG & m_detected;
 
   /* If we have already detected a LOST event, then don't try
    * to do any further processing.
    */
-  if ((m_detected & GSOCK_LOST_FLAG) != 0)
+  if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
   {
     m_establishing = false;
-    return (GSOCK_LOST_FLAG & flags);
+    return (wxSOCKET_LOST_FLAG & flags);
   }
 
   /* Try select now */
@@ -970,23 +1134,23 @@ GSocketEventFlags GSocketBase::Select(GSocketEventFlags flags)
   if (wxFD_ISSET(m_fd, &exceptfds))
   {
     m_establishing = false;
-    m_detected = GSOCK_LOST_FLAG;
+    m_detected = wxSOCKET_LOST_FLAG;
 
     /* LOST event: Abort any further processing */
-    return (GSOCK_LOST_FLAG & flags);
+    return (wxSOCKET_LOST_FLAG & flags);
   }
 
   /* Check for readability */
   if (wxFD_ISSET(m_fd, &readfds))
   {
-    result |= GSOCK_INPUT_FLAG;
+    result |= wxSOCKET_INPUT_FLAG;
 
     if (m_server && m_stream)
     {
       /* This is a TCP server socket that detected a connection.
          While the INPUT_FLAG is also set, it doesn't matter on
          this kind of  sockets, as we can only Accept() from them. */
-      m_detected |= GSOCK_CONNECTION_FLAG;
+      m_detected |= wxSOCKET_CONNECTION_FLAG;
     }
   }
 
@@ -1002,26 +1166,26 @@ GSocketEventFlags GSocketBase::Select(GSocketEventFlags flags)
 
       if (error)
       {
-        m_detected = GSOCK_LOST_FLAG;
+        m_detected = wxSOCKET_LOST_FLAG;
 
         /* LOST event: Abort any further processing */
-        return (GSOCK_LOST_FLAG & flags);
+        return (wxSOCKET_LOST_FLAG & flags);
       }
       else
       {
-        m_detected |= GSOCK_CONNECTION_FLAG;
+        m_detected |= wxSOCKET_CONNECTION_FLAG;
       }
     }
     else
     {
-      result |= GSOCK_OUTPUT_FLAG;
+      result |= wxSOCKET_OUTPUT_FLAG;
     }
   }
 
   return (result | m_detected) & flags;
 }
 
-// All Wait functions poll the socket using GSocket_Select() to
+// All Wait functions poll the socket using Select() to
 // check for the specified combination of conditions, until one
 // of these conditions become true, an error occurs, or the
 // timeout elapses. The polling loop runs the event loop so that
@@ -1030,7 +1194,7 @@ GSocketEventFlags GSocketBase::Select(GSocketEventFlags flags)
 bool
 wxSocketBase::DoWait(long seconds, long milliseconds, wxSocketEventFlags flags)
 {
-    wxCHECK_MSG( m_socket, false, "can't wait on invalid socket" );
+    wxCHECK_MSG( m_impl, false, "can't wait on invalid socket" );
 
     // This can be set to true from Interrupt() to exit this function a.s.a.p.
     m_interrupt = false;
@@ -1063,13 +1227,13 @@ wxSocketBase::DoWait(long seconds, long milliseconds, wxSocketEventFlags flags)
     for ( ;; )
     {
         // We always stop waiting when the connection is lost as it doesn't
-        // make sense to continue further, even if GSOCK_LOST_FLAG is not
+        // make sense to continue further, even if wxSOCKET_LOST_FLAG is not
         // specified in flags to wait for.
-        const GSocketEventFlags
-            result = m_socket->Select(flags | GSOCK_LOST_FLAG);
+        const wxSocketEventFlags
+            result = m_impl->Select(flags | wxSOCKET_LOST_FLAG);
 
         // Incoming connection (server) or connection established (client)?
-        if ( result & GSOCK_CONNECTION_FLAG )
+        if ( result & wxSOCKET_CONNECTION_FLAG )
         {
             m_connected = true;
             m_establishing = false;
@@ -1078,18 +1242,18 @@ wxSocketBase::DoWait(long seconds, long milliseconds, wxSocketEventFlags flags)
         }
 
         // Data available or output buffer ready?
-        if ( (result & GSOCK_INPUT_FLAG) || (result & GSOCK_OUTPUT_FLAG) )
+        if ( (result & wxSOCKET_INPUT_FLAG) || (result & wxSOCKET_OUTPUT_FLAG) )
         {
             gotEvent = true;
             break;
         }
 
         // Connection lost
-        if ( result & GSOCK_LOST_FLAG )
+        if ( result & wxSOCKET_LOST_FLAG )
         {
             m_connected = false;
             m_establishing = false;
-            if ( flags & GSOCK_LOST_FLAG )
+            if ( flags & wxSOCKET_LOST_FLAG )
                 gotEvent = true;
             break;
         }
@@ -1126,10 +1290,10 @@ wxSocketBase::DoWait(long seconds, long milliseconds, wxSocketEventFlags flags)
 bool wxSocketBase::Wait(long seconds, long milliseconds)
 {
     return DoWait(seconds, milliseconds,
-            GSOCK_INPUT_FLAG |
-            GSOCK_OUTPUT_FLAG |
-            GSOCK_CONNECTION_FLAG |
-            GSOCK_LOST_FLAG
+            wxSOCKET_INPUT_FLAG |
+            wxSOCKET_OUTPUT_FLAG |
+            wxSOCKET_CONNECTION_FLAG |
+            wxSOCKET_LOST_FLAG
         );
 }
 
@@ -1139,22 +1303,22 @@ bool wxSocketBase::WaitForRead(long seconds, long milliseconds)
     if ( m_unread )
         return true;
 
-    // Note that GSOCK_INPUT_LOST has to be explicitly passed to DoWait
+    // Note that wxSOCKET_INPUT_LOST has to be explicitly passed to DoWait
     // because of the semantics of WaitForRead: a return value of true means
-    // that a GSocket_Read call will return immediately, not that there is
+    // that a Read call will return immediately, not that there is
     // actually data to read.
-    return DoWait(seconds, milliseconds, GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
+    return DoWait(seconds, milliseconds, wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
 }
 
 
 bool wxSocketBase::WaitForWrite(long seconds, long milliseconds)
 {
-    return DoWait(seconds, milliseconds, GSOCK_OUTPUT_FLAG | GSOCK_LOST_FLAG);
+    return DoWait(seconds, milliseconds, wxSOCKET_OUTPUT_FLAG | wxSOCKET_LOST_FLAG);
 }
 
 bool wxSocketBase::WaitForLost(long seconds, long milliseconds)
 {
-    return DoWait(seconds, milliseconds, GSOCK_LOST_FLAG);
+    return DoWait(seconds, milliseconds, wxSOCKET_LOST_FLAG);
 }
 
 // --------------------------------------------------------------------------
@@ -1169,10 +1333,10 @@ bool wxSocketBase::GetPeer(wxSockAddress& addr_man) const
 {
     GAddress *peer;
 
-    if (!m_socket)
+    if (!m_impl)
         return false;
 
-    peer = m_socket->GetPeer();
+    peer = m_impl->GetPeer();
 
     // copying a null address would just trigger an assert anyway
 
@@ -1189,10 +1353,10 @@ bool wxSocketBase::GetLocal(wxSockAddress& addr_man) const
 {
     GAddress *local;
 
-    if (!m_socket)
+    if (!m_impl)
         return false;
 
-    local = m_socket->GetLocal();
+    local = m_impl->GetLocal();
     addr_man.SetAddress(local);
     GAddress_destroy(local);
 
@@ -1245,8 +1409,8 @@ void wxSocketBase::SetTimeout(long seconds)
 {
     m_timeout = seconds;
 
-    if (m_socket)
-        m_socket->SetTimeout(m_timeout * 1000);
+    if (m_impl)
+        m_impl->SetTimeout(m_timeout * 1000);
 }
 
 void wxSocketBase::SetFlags(wxSocketFlags flags)
@@ -1280,12 +1444,12 @@ void wxSocketBase::OnRequest(wxSocketNotify notification)
             // which are no longer valid.
 
         case wxSOCKET_INPUT:
-            if (m_reading || !m_socket->Select(GSOCK_INPUT_FLAG))
+            if (m_reading || !m_impl->Select(wxSOCKET_INPUT_FLAG))
                 return;
             break;
 
         case wxSOCKET_OUTPUT:
-            if (m_writing || !m_socket->Select(GSOCK_OUTPUT_FLAG))
+            if (m_writing || !m_impl->Select(wxSOCKET_OUTPUT_FLAG))
                 return;
             break;
 
@@ -1293,6 +1457,10 @@ void wxSocketBase::OnRequest(wxSocketNotify notification)
             m_connected = false;
             m_establishing = false;
             break;
+
+        case wxSOCKET_MAX_EVENT:
+            wxFAIL_MSG( "unexpected notification" );
+            return;
     }
 
     // Schedule the event
@@ -1301,10 +1469,10 @@ void wxSocketBase::OnRequest(wxSocketNotify notification)
     wxUnusedVar(flag);
     switch (notification)
     {
-        case GSOCK_INPUT:      flag = GSOCK_INPUT_FLAG; break;
-        case GSOCK_OUTPUT:     flag = GSOCK_OUTPUT_FLAG; break;
-        case GSOCK_CONNECTION: flag = GSOCK_CONNECTION_FLAG; break;
-        case GSOCK_LOST:       flag = GSOCK_LOST_FLAG; break;
+        case wxSOCKET_INPUT:      flag = wxSOCKET_INPUT_FLAG; break;
+        case wxSOCKET_OUTPUT:     flag = wxSOCKET_OUTPUT_FLAG; break;
+        case wxSOCKET_CONNECTION: flag = wxSOCKET_CONNECTION_FLAG; break;
+        case wxSOCKET_LOST:       flag = wxSOCKET_LOST_FLAG; break;
         default:
                                wxLogWarning(_("wxSocket: unknown event!."));
                                return;
@@ -1327,8 +1495,8 @@ void wxSocketBase::OnRequest(wxSocketNotify notification)
 void wxSocketBase::Notify(bool notify)
 {
     m_notify = notify;
-    if (m_socket)
-        m_socket->Notify(notify);
+    if (m_impl)
+        m_impl->Notify(notify);
 }
 
 void wxSocketBase::SetNotify(wxSocketEventFlags flags)
@@ -1410,38 +1578,38 @@ wxSocketServer::wxSocketServer(const wxSockAddress& addr_man,
 {
     wxLogTrace( wxTRACE_Socket, _T("Opening wxSocketServer") );
 
-    m_socket = GSocket::Create(*this);
+    m_impl = wxSocketImpl::Create(*this);
 
-    if (!m_socket)
+    if (!m_impl)
     {
-        wxLogTrace( wxTRACE_Socket, _T("*** GSocket_new failed") );
+        wxLogTrace( wxTRACE_Socket, _T("*** Failed to create m_impl") );
         return;
     }
 
     // Setup the socket as server
-    m_socket->Notify(m_notify);
-    m_socket->SetLocal(addr_man.GetAddress());
+    m_impl->Notify(m_notify);
+    m_impl->SetLocal(addr_man.GetAddress());
 
     if (GetFlags() & wxSOCKET_REUSEADDR) {
-        m_socket->SetReusable();
+        m_impl->SetReusable();
     }
     if (GetFlags() & wxSOCKET_BROADCAST) {
-        m_socket->SetBroadcast();
+        m_impl->SetBroadcast();
     }
     if (GetFlags() & wxSOCKET_NOBIND) {
-        m_socket->DontDoBind();
+        m_impl->DontDoBind();
     }
 
-    if (m_socket->SetServer() != GSOCK_NOERROR)
+    if (m_impl->CreateServer() != wxSOCKET_NOERROR)
     {
-        delete m_socket;
-        m_socket = NULL;
+        delete m_impl;
+        m_impl = NULL;
 
-        wxLogTrace( wxTRACE_Socket, _T("*** GSocket_SetServer failed") );
+        wxLogTrace( wxTRACE_Socket, _T("*** CreateServer() failed") );
         return;
     }
 
-    wxLogTrace( wxTRACE_Socket, _T("wxSocketServer on fd %d"), m_socket->m_fd );
+    wxLogTrace( wxTRACE_Socket, _T("wxSocketServer on fd %d"), m_impl->m_fd );
 }
 
 // --------------------------------------------------------------------------
@@ -1450,16 +1618,16 @@ wxSocketServer::wxSocketServer(const wxSockAddress& addr_man,
 
 bool wxSocketServer::AcceptWith(wxSocketBase& sock, bool wait)
 {
-    if (!m_socket)
+    if (!m_impl)
         return false;
 
     // If wait == false, then the call should be nonblocking.
     // When we are finished, we put the socket to blocking mode
     // again.
-    wxSocketUnblocker unblock(m_socket, !wait);
-    sock.m_socket = m_socket->WaitConnection(sock);
+    wxSocketUnblocker unblock(m_impl, !wait);
+    sock.m_impl = m_impl->WaitConnection(sock);
 
-    if ( !sock.m_socket )
+    if ( !sock.m_impl )
         return false;
 
     sock.m_type = wxSOCKET_BASE;
@@ -1485,32 +1653,30 @@ wxSocketBase *wxSocketServer::Accept(bool wait)
 
 bool wxSocketServer::WaitForAccept(long seconds, long milliseconds)
 {
-    return DoWait(seconds, milliseconds, GSOCK_CONNECTION_FLAG);
+    return DoWait(seconds, milliseconds, wxSOCKET_CONNECTION_FLAG);
 }
 
 bool wxSocketBase::GetOption(int level, int optname, void *optval, int *optlen)
 {
-    wxASSERT_MSG( m_socket, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
 
-    if (m_socket->GetSockOpt(level, optname, optval, optlen)
-        != GSOCK_NOERROR)
-    {
+    SOCKOPTLEN_T lenreal;
+    if ( getsockopt(m_impl->m_fd, level, optname,
+                    static_cast<char *>(optval), &lenreal) != 0 )
         return false;
-    }
+
+    *optlen = lenreal;
+
     return true;
 }
 
-bool wxSocketBase::SetOption(int level, int optname, const void *optval,
-                              int optlen)
+bool
+wxSocketBase::SetOption(int level, int optname, const void *optval, int optlen)
 {
-    wxASSERT_MSG( m_socket, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
 
-    if (m_socket->SetSockOpt(level, optname, optval, optlen)
-        != GSOCK_NOERROR)
-    {
-        return false;
-    }
-    return true;
+    return setsockopt(m_impl->m_fd, level, optname,
+                      static_cast<const char *>(optval), optlen) == 0;
 }
 
 bool wxSocketBase::SetLocal(const wxIPV4address& local)
@@ -1555,36 +1721,36 @@ bool wxSocketClient::DoConnect(const wxSockAddress& addr_man,
                                const wxSockAddress* local,
                                bool wait)
 {
-    if (m_socket)
+    if (m_impl)
     {
         // Shutdown and destroy the socket
         Close();
-        delete m_socket;
+        delete m_impl;
     }
 
-    m_socket = GSocket::Create(*this);
+    m_impl = wxSocketImpl::Create(*this);
     m_connected = false;
     m_establishing = false;
 
-    if (!m_socket)
+    if (!m_impl)
         return false;
 
     // If wait == false, then the call should be nonblocking. When we are
     // finished, we put the socket to blocking mode again.
-    wxSocketUnblocker unblock(m_socket, !wait);
+    wxSocketUnblocker unblock(m_impl, !wait);
 
     // Reuse makes sense for clients too, if we are trying to rebind to the same port
     if (GetFlags() & wxSOCKET_REUSEADDR)
     {
-        m_socket->SetReusable();
+        m_impl->SetReusable();
     }
     if (GetFlags() & wxSOCKET_BROADCAST)
     {
-        m_socket->SetBroadcast();
+        m_impl->SetBroadcast();
     }
     if (GetFlags() & wxSOCKET_NOBIND)
     {
-        m_socket->DontDoBind();
+        m_impl->DontDoBind();
     }
 
     // If no local address was passed and one has been set, use the one that was Set
@@ -1599,22 +1765,20 @@ bool wxSocketClient::DoConnect(const wxSockAddress& addr_man,
         GAddress* la = local->GetAddress();
 
         if (la && la->m_addr)
-            m_socket->SetLocal(la);
+            m_impl->SetLocal(la);
     }
 
-#if defined(__WXMSW__) || defined(__WXGTK__)
-    m_socket->SetInitialSocketBuffers(m_initialRecvBufferSize, m_initialSendBufferSize);
-#endif
+    m_impl->SetInitialSocketBuffers(m_initialRecvBufferSize, m_initialSendBufferSize);
 
-    m_socket->SetPeer(addr_man.GetAddress());
-    const GSocketError err = m_socket->Connect(GSOCK_STREAMED);
+    m_impl->SetPeer(addr_man.GetAddress());
+    const wxSocketError err = m_impl->CreateClient();
 
-    //this will register for callbacks - must be called after m_socket->m_fd was initialized
-    m_socket->Notify(m_notify);
+    //this will register for callbacks - must be called after m_impl->m_fd was initialized
+    m_impl->Notify(m_notify);
 
-    if (err != GSOCK_NOERROR)
+    if (err != wxSOCKET_NOERROR)
     {
-        if (err == GSOCK_WOULDBLOCK)
+        if (err == wxSOCKET_WOULDBLOCK)
             m_establishing = true;
 
         return false;
@@ -1645,52 +1809,51 @@ bool wxSocketClient::WaitOnConnect(long seconds, long milliseconds)
         return true;
     }
 
-    wxCHECK_MSG( m_establishing && m_socket, false,
+    wxCHECK_MSG( m_establishing && m_impl, false,
                  "No connection establishment attempt in progress" );
 
-    // we must specify GSOCK_LOST_FLAG here explicitly because we must return
+    // we must specify wxSOCKET_LOST_FLAG here explicitly because we must return
     // true if the connection establishment process is finished, whether it is
     // over because we successfully connected or because we were not able to
     // connect
     return DoWait(seconds, milliseconds,
-        GSOCK_CONNECTION_FLAG | GSOCK_LOST_FLAG);
+        wxSOCKET_CONNECTION_FLAG | wxSOCKET_LOST_FLAG);
 }
 
 // ==========================================================================
 // wxDatagramSocket
 // ==========================================================================
 
-/* NOTE: experimental stuff - might change */
-
 wxDatagramSocket::wxDatagramSocket( const wxSockAddress& addr,
                                     wxSocketFlags flags )
                 : wxSocketBase( flags, wxSOCKET_DATAGRAM )
 {
     // Create the socket
-    m_socket = GSocket::Create(*this);
+    m_impl = wxSocketImpl::Create(*this);
 
-    if (!m_socket)
+    if (!m_impl)
         return;
 
-    m_socket->Notify(m_notify);
+    m_impl->Notify(m_notify);
     // Setup the socket as non connection oriented
-    m_socket->SetLocal(addr.GetAddress());
+    m_impl->SetLocal(addr.GetAddress());
     if (flags & wxSOCKET_REUSEADDR)
     {
-        m_socket->SetReusable();
+        m_impl->SetReusable();
     }
     if (GetFlags() & wxSOCKET_BROADCAST)
     {
-        m_socket->SetBroadcast();
+        m_impl->SetBroadcast();
     }
     if (GetFlags() & wxSOCKET_NOBIND)
     {
-        m_socket->DontDoBind();
+        m_impl->DontDoBind();
     }
-    if ( m_socket->SetNonOriented() != GSOCK_NOERROR )
+
+    if ( m_impl->CreateUDP() != wxSOCKET_NOERROR )
     {
-        delete m_socket;
-        m_socket = NULL;
+        delete m_impl;
+        m_impl = NULL;
         return;
     }
 
@@ -1712,9 +1875,9 @@ wxDatagramSocket& wxDatagramSocket::SendTo( const wxSockAddress& addr,
                                             const void* buf,
                                             wxUint32 nBytes )
 {
-    wxASSERT_MSG( m_socket, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
 
-    m_socket->SetPeer(addr.GetAddress());
+    m_impl->SetPeer(addr.GetAddress());
     Write(buf, nBytes);
     return (*this);
 }
@@ -1728,7 +1891,8 @@ class wxSocketModule : public wxModule
 public:
     virtual bool OnInit()
     {
-        // wxSocketBase will call GSocket_Init() itself when/if needed
+        // wxSocketBase will call Initialize() itself only if sockets are
+        // really used, don't do it from here
         return true;
     }
 
index 0c034edfeff5167f049382e243aac3a17661cb90..c847b5a2ad922b85b83af16ed408d7393f7cbcde 100644 (file)
 
 extern "C" {
 static
-void _GSocket_GDK_Input(gpointer data,
+void wxSocket_GDK_Input(gpointer data,
                         gint WXUNUSED(source),
                         GdkInputCondition condition)
 {
-  GSocket *socket = (GSocket *)data;
+    wxSocketImpl * const socket = static_cast<wxSocketImpl *>(data);
 
-  if (condition & GDK_INPUT_READ)
-    socket->Detected_Read();
-  if (condition & GDK_INPUT_WRITE)
-    socket->Detected_Write();
+    if ( condition & GDK_INPUT_READ )
+        socket->Detected_Read();
+    if ( condition & GDK_INPUT_WRITE )
+        socket->Detected_Write();
 }
 }
 
-class GTKSocketManager : public GSocketInputBasedManager
+class GTKSocketManager : public wxSocketInputBasedManager
 {
 public:
-    virtual int AddInput(GSocket *socket, SocketDir d)
+    virtual int AddInput(wxSocketImpl *socket, SocketDir d)
     {
         return gdk_input_add
                (
                     socket->m_fd,
                     d == FD_OUTPUT ? GDK_INPUT_WRITE : GDK_INPUT_READ,
-                    _GSocket_GDK_Input,
+                    wxSocket_GDK_Input,
                     socket
                );
     }
@@ -57,7 +57,7 @@ public:
     }
 };
 
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
 {
     static GTKSocketManager s_manager;
     return &s_manager;
index 0c034edfeff5167f049382e243aac3a17661cb90..8a6eab720cb59c10905e0a07c52b56c18bac6730 100644 (file)
 
 extern "C" {
 static
-void _GSocket_GDK_Input(gpointer data,
+void wxSocket_GDK_Input(gpointer data,
                         gint WXUNUSED(source),
                         GdkInputCondition condition)
 {
-  GSocket *socket = (GSocket *)data;
+  wxSocketImpl const *socket = static_cast<wxSocketImpl *>(data);
 
-  if (condition & GDK_INPUT_READ)
+  if ( condition & GDK_INPUT_READ )
     socket->Detected_Read();
-  if (condition & GDK_INPUT_WRITE)
+  if ( condition & GDK_INPUT_WRITE )
     socket->Detected_Write();
 }
 }
 
-class GTKSocketManager : public GSocketInputBasedManager
+class GTKSocketManager : public wxSocketInputBasedManager
 {
 public:
-    virtual int AddInput(GSocket *socket, SocketDir d)
+    virtual int AddInput(wxSocketImpl *socket, SocketDir d)
     {
         return gdk_input_add
                (
                     socket->m_fd,
                     d == FD_OUTPUT ? GDK_INPUT_WRITE : GDK_INPUT_READ,
-                    _GSocket_GDK_Input,
+                    wxSocket_GDK_Input,
                     socket
                );
     }
@@ -57,7 +57,7 @@ public:
     }
 };
 
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
 {
     static GTKSocketManager s_manager;
     return &s_manager;
index 144eb61cd83697f890deea45484f3306b3b45ffa..468489d229e1ae2e120b8211c683c936b64166c8 100644 (file)
 
 extern "C" {
 
-static void _GSocket_Motif_Input(XtPointer data, int *WXUNUSED(fid),
+static void wxSocket_Motif_Input(XtPointer data, int *WXUNUSED(fid),
                                  XtInputId *WXUNUSED(id))
 {
-    GSocket *socket = (GSocket *)data;
+    wxSocketImpl * const socket = static_cast<wxSocketImpl *>(data);
 
     socket->Detected_Read();
 }
 
-static void _GSocket_Motif_Output(XtPointer data, int *WXUNUSED(fid),
+static void wxSocket_Motif_Output(XtPointer data, int *WXUNUSED(fid),
                                   XtInputId *WXUNUSED(id))
 {
-    GSocket *socket = (GSocket *)data;
+    wxSocketImpl * const socket = static_cast<wxSocketImpl *>(data);
 
     socket->Detected_Write();
 }
 
 }
 
-class MotifSocketManager : public GSocketInputBasedManager
+class MotifSocketManager : public wxSocketInputBasedManager
 {
 public:
-    virtual int AddInput(GSocket *socket, SocketDir d)
+    virtual int AddInput(wxSocketImpl *socket, SocketDir d)
     {
         return XtAppAddInput
                (
@@ -49,8 +49,8 @@ public:
                     socket->m_fd,
                     (XtPointer)(d == FD_OUTPUT ? XtInputWriteMask
                                                : XtInputReadMask),
-                    d == FD_OUTPUT ? _GSocket_Motif_Output
-                                   : _GSocket_Motif_Input,
+                    d == FD_OUTPUT ? wxSocket_Motif_Output
+                                   : wxSocket_Motif_Input,
                     socket
                );
     }
@@ -61,7 +61,7 @@ public:
     }
 };
 
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
 {
     static MotifSocketManager s_manager;
     return &s_manager;
index 5af350eb5a6ec9841e4bf11585b6ef80fb0f1a34..3ef53a321bd94f8ceccc04a7fcd209b70dfffcfc 100644 (file)
@@ -42,8 +42,6 @@
 // wxAppTraits implementation
 // ============================================================================
 
-GSocketManager *wxAppTraits::ms_manager = NULL;
-
 WXDWORD wxAppTraits::DoSimpleWaitForThread(WXHANDLE hThread)
 {
     return ::WaitForSingleObject((HANDLE)hThread, INFINITE);
index 96af8168363e03ec182efb3afaa6bed6222a564e..f611abaea5531b9dc11fd7919dba709c47001c83 100644 (file)
@@ -1,10 +1,10 @@
 /* -------------------------------------------------------------------------
- * Project:     GSocket (Generic Socket)
+ * Project:     wxSocketImpl (Generic Socket)
  * Name:        src/msw/gsocket.cpp
  * Copyright:   (c) Guilhem Lavaux
  * Licence:     wxWindows Licence
  * Author:      Guillermo Rodriguez Garcia <guille@iies.es>
- * Purpose:     GSocket main MSW file
+ * Purpose:     wxSocketImpl main MSW file
  * Licence:     The wxWindows licence
  * CVSID:       $Id$
  * -------------------------------------------------------------------------
@@ -77,146 +77,58 @@ wxFORCE_LINK_MODULE(gsockmsw)
 
 #include "wx/private/socket.h"
 
-bool GSocket_Init()
+void wxSocketImplMSW::DoClose()
 {
-  WSADATA wsaData;
+    wxSocketManager::Get()->
+        Uninstall_Callback(this, wxSOCKET_MAX_EVENT /* unused anyhow */);
 
-  GSocketManager * const manager = GSocketManager::Get();
-  if ( !manager || !manager->OnInit() )
-      return false;
-
-  /* Initialize WinSocket */
-  return WSAStartup((1 << 8) | 1, &wsaData) == 0;
-}
-
-void GSocket_Cleanup()
-{
-  GSocketManager * const manager = GSocketManager::Get();
-  if ( manager )
-    manager->OnExit();
-
-  /* Cleanup WinSocket */
-  WSACleanup();
+    closesocket(m_fd);
 }
 
-/* Constructors / Destructors for GSocket */
-
-/* Server specific parts */
-
-/* GSocket_SetServer:
- *  Sets up this socket as a server. The local address must have been
- *  set with GSocket_SetLocal() before GSocket_SetServer() is called.
- *  Returns GSOCK_NOERROR on success, one of the following otherwise:
- *
- *  Error codes:
- *    GSOCK_INVSOCK - the socket is in use.
- *    GSOCK_INVADDR - the local address has not been set.
- *    GSOCK_IOERR   - low-level error.
- */
-GSocketError GSocket::SetServer()
-{
-  u_long arg = 1;
-
-  /* must not be in use */
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  /* the local addr must have been set */
-  if (!m_local)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Initialize all fields */
-  m_server   = true;
-  m_stream   = true;
-
-  /* Create the socket */
-  m_fd = socket(m_local->m_realfamily, SOCK_STREAM, 0);
-
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
-  GSocketManager::Get()->Install_Callback(this);
-
-  /* allow a socket to re-bind if the socket is in the TIME_WAIT
-     state after being previously closed.
-   */
-  if (m_reusable)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-  }
-
-  /* Bind to the local address,
-   * retrieve the actual address bound,
-   * and listen up to 5 connections.
-   */
-  if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
-      (getsockname(m_fd,
-                   m_local->m_addr,
-                   (WX_SOCKLEN_T *)&m_local->m_len) != 0) ||
-      (listen(m_fd, 5) != 0))
-  {
-    Close();
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  return GSOCK_NOERROR;
-}
-
-/* GSocket_WaitConnection:
+/*
  *  Waits for an incoming client connection. Returns a pointer to
- *  a GSocket object, or NULL if there was an error, in which case
- *  the last error field will be updated for the calling GSocket.
+ *  a wxSocketImpl object, or NULL if there was an error, in which case
+ *  the last error field will be updated for the calling wxSocketImpl.
  *
- *  Error codes (set in the calling GSocket)
- *    GSOCK_INVSOCK    - the socket is not valid or not a server.
- *    GSOCK_TIMEDOUT   - timeout, no incoming connections.
- *    GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
- *    GSOCK_MEMERR     - couldn't allocate memory.
- *    GSOCK_IOERR      - low-level error.
+ *  Error codes (set in the calling wxSocketImpl)
+ *    wxSOCKET_INVSOCK    - the socket is not valid or not a server.
+ *    wxSOCKET_TIMEDOUT   - timeout, no incoming connections.
+ *    wxSOCKET_WOULDBLOCK - the call would block and the socket is nonblocking.
+ *    wxSOCKET_MEMERR     - couldn't allocate memory.
+ *    wxSOCKET_IOERR      - low-level error.
  */
-GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
+wxSocketImpl *wxSocketImplMSW::WaitConnection(wxSocketBase& wxsocket)
 {
-  GSocket *connection;
+  wxSocketImpl *connection;
   wxSockAddr from;
   WX_SOCKLEN_T fromlen = sizeof(from);
-  GSocketError err;
+  wxSocketError err;
   u_long arg = 1;
 
   /* Reenable CONNECTION events */
-  m_detected &= ~GSOCK_CONNECTION_FLAG;
+  m_detected &= ~wxSOCKET_CONNECTION_FLAG;
 
   /* If the socket has already been created, we exit immediately */
   if (m_fd == INVALID_SOCKET || !m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return NULL;
   }
 
-  /* Create a GSocket object for the new connection */
-  connection = GSocket::Create(wxsocket);
+  /* Create a wxSocketImpl object for the new connection */
+  connection = wxSocketImplMSW::Create(wxsocket);
 
   if (!connection)
   {
-    m_error = GSOCK_MEMERR;
+    m_error = wxSOCKET_MEMERR;
     return NULL;
   }
 
   /* Wait for a connection (with timeout) */
-  if (Input_Timeout() == GSOCK_TIMEDOUT)
+  if (Input_Timeout() == wxSOCKET_TIMEDOUT)
   {
     delete connection;
-    /* m_error set by _GSocket_Input_Timeout */
+    /* m_error set by Input_Timeout */
     return NULL;
   }
 
@@ -225,9 +137,9 @@ GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
   if (connection->m_fd == INVALID_SOCKET)
   {
     if (WSAGetLastError() == WSAEWOULDBLOCK)
-      m_error = GSOCK_WOULDBLOCK;
+      m_error = wxSOCKET_WOULDBLOCK;
     else
-      m_error = GSOCK_IOERR;
+      m_error = wxSOCKET_IOERR;
 
     delete connection;
     return NULL;
@@ -242,11 +154,11 @@ GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
   if (!connection->m_peer)
   {
     delete connection;
-    m_error = GSOCK_MEMERR;
+    m_error = wxSOCKET_MEMERR;
     return NULL;
   }
   err = _GAddress_translate_from(connection->m_peer, (sockaddr*)&from, fromlen);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     GAddress_destroy(connection->m_peer);
     delete connection;
@@ -255,278 +167,80 @@ GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
   }
 
   ioctlsocket(connection->m_fd, FIONBIO, (u_long FAR *) &arg);
-  GSocketManager::Get()->Install_Callback(connection);
+  wxSocketManager::Get()->Install_Callback(connection);
 
   return connection;
 }
 
-/* GSocket_SetReusable:
-*  Simply sets the m_resuable flag on the socket. GSocket_SetServer will
-*  make the appropriate setsockopt() call.
-*  Implemented as a GSocket function because clients (ie, wxSocketServer)
-*  don't have access to the GSocket struct information.
-*  Returns true if the flag was set correctly, false if an error occurred
-*  (ie, if the parameter was NULL)
-*/
-bool GSocket::SetReusable()
-{
-    /* socket must not be null, and must not be in use/already bound */
-    if (this && m_fd == INVALID_SOCKET) {
-        m_reusable = true;
-        return true;
-    }
-    return false;
-}
-
-/* GSocket_SetBroadcast:
-*  Simply sets the m_broadcast flag on the socket. GSocket_SetServer will
-*  make the appropriate setsockopt() call.
-*  Implemented as a GSocket function because clients (ie, wxSocketServer)
-*  don't have access to the GSocket struct information.
-*  Returns true if the flag was set correctly, false if an error occurred
-*  (ie, if the parameter was NULL)
-*/
-bool GSocket::SetBroadcast()
-{
-    /* socket must not be in use/already bound */
-    if (m_fd == INVALID_SOCKET) {
-        m_broadcast = true;
-        return true;
-    }
-    return false;
-}
-
-bool GSocket::DontDoBind()
-{
-    /* socket must not be in use/already bound */
-    if (m_fd == INVALID_SOCKET) {
-        m_dobind = false;
-        return true;
-    }
-    return false;
-}
-
-/* Client specific parts */
-
-/* GSocket_Connect:
- *  For stream (connection oriented) sockets, GSocket_Connect() tries
- *  to establish a client connection to a server using the peer address
- *  as established with GSocket_SetPeer(). Returns GSOCK_NOERROR if the
- *  connection has been successfully established, or one of the error
- *  codes listed below. Note that for nonblocking sockets, a return
- *  value of GSOCK_WOULDBLOCK doesn't mean a failure. The connection
- *  request can be completed later; you should use GSocket_Select()
- *  to poll for GSOCK_CONNECTION | GSOCK_LOST, or wait for the
- *  corresponding asynchronous events.
- *
- *  For datagram (non connection oriented) sockets, GSocket_Connect()
- *  just sets the peer address established with GSocket_SetPeer() as
- *  default destination.
- *
- *  Error codes:
- *    GSOCK_INVSOCK    - the socket is in use or not valid.
- *    GSOCK_INVADDR    - the peer address has not been established.
- *    GSOCK_TIMEDOUT   - timeout, the connection failed.
- *    GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
- *    GSOCK_MEMERR     - couldn't allocate memory.
- *    GSOCK_IOERR      - low-level error.
- */
-GSocketError GSocket::Connect(GSocketStream stream)
+wxSocketError wxSocketImplMSW::DoHandleConnect(int ret)
 {
-  int ret, err;
-  u_long arg = 1;
-
-  /* Enable CONNECTION events (needed for nonblocking connections) */
-  m_detected &= ~GSOCK_CONNECTION_FLAG;
-
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  if (!m_peer)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Streamed or dgram socket? */
-  m_stream   = (stream == GSOCK_STREAMED);
-  m_server   = false;
-  m_establishing = false;
-
-  /* Create the socket */
-  m_fd = socket(m_peer->m_realfamily,
-                     m_stream? SOCK_STREAM : SOCK_DGRAM, 0);
-
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
-  GSocketManager::Get()->Install_Callback(this);
-
-  // If the reuse flag is set, use the applicable socket reuse flag
-  if (m_reusable)
-  {
-     setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-  }
-
-  if (m_initialRecvBufferSize >= 0)
-    setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
-  if (m_initialSendBufferSize >= 0)
-    setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
-
-  // If a local address has been set, then we need to bind to it before calling connect
-  if (m_local && m_local->m_addr)
-  {
-    bind(m_fd, m_local->m_addr, m_local->m_len);
-  }
-
-  /* Connect it to the peer address, with a timeout (see below) */
-  ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
-
-  if (ret == SOCKET_ERROR)
-  {
-    err = WSAGetLastError();
-
-    /* If connect failed with EWOULDBLOCK and the GSocket object
-     * is in blocking mode, we select() for the specified timeout
-     * checking for writability to see if the connection request
-     * completes.
-     */
-    if ((err == WSAEWOULDBLOCK) && (!m_non_blocking))
+    // TODO: review this
+    if (ret == SOCKET_ERROR)
     {
-      err = Connect_Timeout();
-
-      if (err != GSOCK_NOERROR)
-      {
+        int err = WSAGetLastError();
+
+        /* If connect failed with EWOULDBLOCK and the wxSocketImpl object
+         * is in blocking mode, we select() for the specified timeout
+         * checking for writability to see if the connection request
+         * completes.
+         */
+        if ((err == WSAEWOULDBLOCK) && (!m_non_blocking))
+        {
+            err = Connect_Timeout();
+
+            if (err != wxSOCKET_NOERROR)
+            {
+                Close();
+                /* m_error is set in Connect_Timeout */
+            }
+
+            return (wxSocketError) err;
+        }
+
+        /* If connect failed with EWOULDBLOCK and the wxSocketImpl object
+         * is set to nonblocking, we set m_error to wxSOCKET_WOULDBLOCK
+         * (and return wxSOCKET_WOULDBLOCK) but we don't close the socket;
+         * this way if the connection completes, a wxSOCKET_CONNECTION
+         * event will be generated, if enabled.
+         */
+        if ((err == WSAEWOULDBLOCK) && (m_non_blocking))
+        {
+            m_establishing = true;
+            m_error = wxSOCKET_WOULDBLOCK;
+            return wxSOCKET_WOULDBLOCK;
+        }
+
+        /* If connect failed with an error other than EWOULDBLOCK,
+         * then the call to Connect() has failed.
+         */
         Close();
-        /* m_error is set in _GSocket_Connect_Timeout */
-      }
-
-      return (GSocketError) err;
+        m_error = wxSOCKET_IOERR;
+        return wxSOCKET_IOERR;
     }
 
-    /* If connect failed with EWOULDBLOCK and the GSocket object
-     * is set to nonblocking, we set m_error to GSOCK_WOULDBLOCK
-     * (and return GSOCK_WOULDBLOCK) but we don't close the socket;
-     * this way if the connection completes, a GSOCK_CONNECTION
-     * event will be generated, if enabled.
-     */
-    if ((err == WSAEWOULDBLOCK) && (m_non_blocking))
-    {
-      m_establishing = true;
-      m_error = GSOCK_WOULDBLOCK;
-      return GSOCK_WOULDBLOCK;
-    }
-
-    /* If connect failed with an error other than EWOULDBLOCK,
-     * then the call to GSocket_Connect() has failed.
-     */
-    Close();
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  return GSOCK_NOERROR;
-}
-
-/* Datagram sockets */
-
-/* GSocket_SetNonOriented:
- *  Sets up this socket as a non-connection oriented (datagram) socket.
- *  Before using this function, the local address must have been set
- *  with GSocket_SetLocal(), or the call will fail. Returns GSOCK_NOERROR
- *  on success, or one of the following otherwise.
- *
- *  Error codes:
- *    GSOCK_INVSOCK - the socket is in use.
- *    GSOCK_INVADDR - the local address has not been set.
- *    GSOCK_IOERR   - low-level error.
- */
-GSocketError GSocket::SetNonOriented()
-{
-  u_long arg = 1;
-
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  if (!m_local)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Initialize all fields */
-  m_stream   = false;
-  m_server   = false;
-
-  /* Create the socket */
-  m_fd = socket(m_local->m_realfamily, SOCK_DGRAM, 0);
-
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
-  GSocketManager::Get()->Install_Callback(this);
-
-  if (m_reusable)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-  }
-  if (m_broadcast)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST, (const char*)&arg, sizeof(arg));
-  }
-  if (m_dobind)
-  {
-    /* Bind to the local address,
-     * and retrieve the actual address bound.
-     */
-    if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
-        (getsockname(m_fd,
-                     m_local->m_addr,
-                     (WX_SOCKLEN_T *)&m_local->m_len) != 0))
-    {
-      Close();
-      m_error = GSOCK_IOERR;
-      return GSOCK_IOERR;
-    }
-  }
-
-  return GSOCK_NOERROR;
+    return wxSOCKET_NOERROR;
 }
 
 /* Generic IO */
 
 /* Like recv(), send(), ... */
-int GSocket::Read(char *buffer, int size)
+int wxSocketImplMSW::Read(char *buffer, int size)
 {
   int ret;
 
   /* Reenable INPUT events */
-  m_detected &= ~GSOCK_INPUT_FLAG;
+  m_detected &= ~wxSOCKET_INPUT_FLAG;
 
   if (m_fd == INVALID_SOCKET || m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return -1;
   }
 
   /* If the socket is blocking, wait for data (with a timeout) */
-  if (Input_Timeout() == GSOCK_TIMEDOUT)
+  if (Input_Timeout() == wxSOCKET_TIMEDOUT)
   {
-    m_error = GSOCK_TIMEDOUT;
+    m_error = wxSOCKET_TIMEDOUT;
     return -1;
   }
 
@@ -539,27 +253,27 @@ int GSocket::Read(char *buffer, int size)
   if (ret == SOCKET_ERROR)
   {
     if (WSAGetLastError() != WSAEWOULDBLOCK)
-      m_error = GSOCK_IOERR;
+      m_error = wxSOCKET_IOERR;
     else
-      m_error = GSOCK_WOULDBLOCK;
+      m_error = wxSOCKET_WOULDBLOCK;
     return -1;
   }
 
   return ret;
 }
 
-int GSocket::Write(const char *buffer, int size)
+int wxSocketImplMSW::Write(const char *buffer, int size)
 {
   int ret;
 
   if (m_fd == INVALID_SOCKET || m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return -1;
   }
 
   /* If the socket is blocking, wait for writability (with a timeout) */
-  if (Output_Timeout() == GSOCK_TIMEDOUT)
+  if (Output_Timeout() == wxSOCKET_TIMEDOUT)
     return -1;
 
   /* Write the data */
@@ -571,70 +285,29 @@ int GSocket::Write(const char *buffer, int size)
   if (ret == SOCKET_ERROR)
   {
     if (WSAGetLastError() != WSAEWOULDBLOCK)
-      m_error = GSOCK_IOERR;
+      m_error = wxSOCKET_IOERR;
     else
-      m_error = GSOCK_WOULDBLOCK;
+      m_error = wxSOCKET_WOULDBLOCK;
 
     /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
      * does). Once the first OUTPUT event is received, users can assume
      * that the socket is writable until a read operation fails. Only then
      * will further OUTPUT events be posted.
      */
-    m_detected &= ~GSOCK_OUTPUT_FLAG;
+    m_detected &= ~wxSOCKET_OUTPUT_FLAG;
     return -1;
   }
 
   return ret;
 }
 
-/* Attributes */
-
-/* GSocket_SetNonBlocking:
- *  Sets the socket to non-blocking mode. All IO calls will return
- *  immediately.
- */
-void GSocket::SetNonBlocking(bool non_block)
-{
-  m_non_blocking = non_block;
-}
-
-/* GSocket_GetError:
- *  Returns the last error occurred for this socket. Note that successful
- *  operations do not clear this back to GSOCK_NOERROR, so use it only
- *  after an error.
- */
-GSocketError WXDLLIMPEXP_NET GSocket::GetError()
-{
-  return m_error;
-}
-
-GSocketError GSocket::GetSockOpt(int level, int optname,
-                                void *optval, int *optlen)
-{
-    if (getsockopt(m_fd, level, optname, (char*)optval, optlen) == 0)
-    {
-        return GSOCK_NOERROR;
-    }
-    return GSOCK_OPTERR;
-}
-
-GSocketError GSocket::SetSockOpt(int level, int optname,
-                                const void *optval, int optlen)
-{
-    if (setsockopt(m_fd, level, optname, (char*)optval, optlen) == 0)
-    {
-        return GSOCK_NOERROR;
-    }
-    return GSOCK_OPTERR;
-}
-
 /* Internals (IO) */
 
-/* _GSocket_Input_Timeout:
+/*
  *  For blocking sockets, wait until data is available or
  *  until timeout ellapses.
  */
-GSocketError GSocket::Input_Timeout()
+wxSocketError wxSocketImplMSW::Input_Timeout()
 {
   fd_set readfds;
 
@@ -644,18 +317,18 @@ GSocketError GSocket::Input_Timeout()
     FD_SET(m_fd, &readfds);
     if (select(0, &readfds, NULL, NULL, &m_timeout) == 0)
     {
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
   }
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-/* _GSocket_Output_Timeout:
+/*
  *  For blocking sockets, wait until data can be sent without
  *  blocking or until timeout ellapses.
  */
-GSocketError GSocket::Output_Timeout()
+wxSocketError wxSocketImplMSW::Output_Timeout()
 {
   fd_set writefds;
 
@@ -665,18 +338,18 @@ GSocketError GSocket::Output_Timeout()
     FD_SET(m_fd, &writefds);
     if (select(0, NULL, &writefds, NULL, &m_timeout) == 0)
     {
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
   }
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-/* _GSocket_Connect_Timeout:
+/*
  *  For blocking sockets, wait until the connection is
  *  established or fails, or until timeout ellapses.
  */
-GSocketError GSocket::Connect_Timeout()
+wxSocketError wxSocketImplMSW::Connect_Timeout()
 {
   fd_set writefds;
   fd_set exceptfds;
@@ -687,47 +360,47 @@ GSocketError GSocket::Connect_Timeout()
   FD_SET(m_fd, &exceptfds);
   if (select(0, NULL, &writefds, &exceptfds, &m_timeout) == 0)
   {
-    m_error = GSOCK_TIMEDOUT;
-    return GSOCK_TIMEDOUT;
+    m_error = wxSOCKET_TIMEDOUT;
+    return wxSOCKET_TIMEDOUT;
   }
   if (!FD_ISSET(m_fd, &writefds))
   {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
+    m_error = wxSOCKET_IOERR;
+    return wxSOCKET_IOERR;
   }
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-int GSocket::Recv_Stream(char *buffer, int size)
+int wxSocketImplMSW::Recv_Stream(char *buffer, int size)
 {
   return recv(m_fd, buffer, size, 0);
 }
 
-int GSocket::Recv_Dgram(char *buffer, int size)
+int wxSocketImplMSW::Recv_Dgram(char *buffer, int size)
 {
   wxSockAddr from;
   WX_SOCKLEN_T fromlen = sizeof(from);
   int ret;
-  GSocketError err;
+  wxSocketError err;
 
   ret = recvfrom(m_fd, buffer, size, 0, (sockaddr*)&from, &fromlen);
 
   if (ret == SOCKET_ERROR)
     return SOCKET_ERROR;
 
-  /* Translate a system address into a GSocket address */
+  /* Translate a system address into a wxSocketImpl address */
   if (!m_peer)
   {
     m_peer = GAddress_new();
     if (!m_peer)
     {
-      m_error = GSOCK_MEMERR;
+      m_error = wxSOCKET_MEMERR;
       return -1;
     }
   }
   err = _GAddress_translate_from(m_peer, (sockaddr*)&from, fromlen);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     GAddress_destroy(m_peer);
     m_peer  = NULL;
@@ -738,25 +411,25 @@ int GSocket::Recv_Dgram(char *buffer, int size)
   return ret;
 }
 
-int GSocket::Send_Stream(const char *buffer, int size)
+int wxSocketImplMSW::Send_Stream(const char *buffer, int size)
 {
   return send(m_fd, buffer, size, 0);
 }
 
-int GSocket::Send_Dgram(const char *buffer, int size)
+int wxSocketImplMSW::Send_Dgram(const char *buffer, int size)
 {
   struct sockaddr *addr;
   int len, ret;
-  GSocketError err;
+  wxSocketError err;
 
   if (!m_peer)
   {
-    m_error = GSOCK_INVADDR;
+    m_error = wxSOCKET_INVADDR;
     return -1;
   }
 
   err = _GAddress_translate_to(m_peer, &addr, &len);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     m_error = err;
     return -1;
@@ -777,32 +450,32 @@ int GSocket::Send_Dgram(const char *buffer, int size)
  */
 
 /* CHECK_ADDRESS verifies that the current address family is either
- * GSOCK_NOFAMILY or GSOCK_*family*, and if it is GSOCK_NOFAMILY, it
- * initalizes it to be a GSOCK_*family*. In other cases, it returns
+ * wxSOCKET_NOFAMILY or wxSOCKET_*family*, and if it is wxSOCKET_NOFAMILY, it
+ * initalizes it to be a wxSOCKET_*family*. In other cases, it returns
  * an appropiate error code.
  *
  * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error.
  */
 #define CHECK_ADDRESS(address, family)                              \
 {                                                                   \
-  if (address->m_family == GSOCK_NOFAMILY)                          \
-    if (_GAddress_Init_##family(address) != GSOCK_NOERROR)          \
+  if (address->m_family == wxSOCKET_NOFAMILY)                          \
+    if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \
       return address->m_error;                                      \
-  if (address->m_family != GSOCK_##family)                          \
+  if (address->m_family != wxSOCKET_##family)                          \
   {                                                                 \
-    address->m_error = GSOCK_INVADDR;                               \
-    return GSOCK_INVADDR;                                           \
+    address->m_error = wxSOCKET_INVADDR;                               \
+    return wxSOCKET_INVADDR;                                           \
   }                                                                 \
 }
 
 #define CHECK_ADDRESS_RETVAL(address, family, retval)               \
 {                                                                   \
-  if (address->m_family == GSOCK_NOFAMILY)                          \
-    if (_GAddress_Init_##family(address) != GSOCK_NOERROR)          \
+  if (address->m_family == wxSOCKET_NOFAMILY)                          \
+    if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \
       return retval;                                                \
-  if (address->m_family != GSOCK_##family)                          \
+  if (address->m_family != wxSOCKET_##family)                          \
   {                                                                 \
-    address->m_error = GSOCK_INVADDR;                               \
+    address->m_error = wxSOCKET_INVADDR;                               \
     return retval;                                                  \
   }                                                                 \
 }
@@ -815,7 +488,7 @@ GAddress *GAddress_new()
   if ((address = (GAddress *) malloc(sizeof(GAddress))) == NULL)
     return NULL;
 
-  address->m_family = GSOCK_NOFAMILY;
+  address->m_family = wxSOCKET_NOFAMILY;
   address->m_addr   = NULL;
   address->m_len    = 0;
 
@@ -863,27 +536,27 @@ GAddressType GAddress_GetFamily(GAddress *address)
   return address->m_family;
 }
 
-GSocketError _GAddress_translate_from(GAddress *address,
+wxSocketError _GAddress_translate_from(GAddress *address,
                                       struct sockaddr *addr, int len)
 {
   address->m_realfamily = addr->sa_family;
   switch (addr->sa_family)
   {
     case AF_INET:
-      address->m_family = GSOCK_INET;
+      address->m_family = wxSOCKET_INET;
       break;
     case AF_UNIX:
-      address->m_family = GSOCK_UNIX;
+      address->m_family = wxSOCKET_UNIX;
       break;
 #if wxUSE_IPV6
     case AF_INET6:
-      address->m_family = GSOCK_INET6;
+      address->m_family = wxSOCKET_INET6;
       break;
 #endif
     default:
     {
-      address->m_error = GSOCK_INVOP;
-      return GSOCK_INVOP;
+      address->m_error = wxSOCKET_INVOP;
+      return wxSOCKET_INVOP;
     }
   }
 
@@ -895,33 +568,33 @@ GSocketError _GAddress_translate_from(GAddress *address,
 
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
   memcpy(address->m_addr, addr, len);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError _GAddress_translate_to(GAddress *address,
+wxSocketError _GAddress_translate_to(GAddress *address,
                                     struct sockaddr **addr, int *len)
 {
   if (!address->m_addr)
   {
-    address->m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
+    address->m_error = wxSOCKET_INVADDR;
+    return wxSOCKET_INVADDR;
   }
 
   *len = address->m_len;
   *addr = (struct sockaddr *) malloc(address->m_len);
   if (*addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
   memcpy(*addr, address->m_addr, address->m_len);
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 /*
@@ -930,25 +603,25 @@ GSocketError _GAddress_translate_to(GAddress *address,
  * -------------------------------------------------------------------------
  */
 
-GSocketError _GAddress_Init_INET(GAddress *address)
+wxSocketError _GAddress_Init_INET(GAddress *address)
 {
   address->m_len  = sizeof(struct sockaddr_in);
   address->m_addr = (struct sockaddr *) malloc(address->m_len);
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
-  address->m_family = GSOCK_INET;
+  address->m_family = wxSOCKET_INET;
   address->m_realfamily = AF_INET;
   ((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET;
   ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_ANY;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
+wxSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
 {
   struct hostent *he;
   struct in_addr *addr;
@@ -968,26 +641,26 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
     if ((he = gethostbyname(hostname)) == NULL)
     {
       /* addr->s_addr = INADDR_NONE just done by inet_addr() above */
-      address->m_error = GSOCK_NOHOST;
-      return GSOCK_NOHOST;
+      address->m_error = wxSOCKET_NOHOST;
+      return wxSOCKET_NOHOST;
     }
     array_addr = (struct in_addr *) *(he->h_addr_list);
     addr->s_addr = array_addr[0].s_addr;
   }
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
+wxSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
 {
   return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
 }
 
-GSocketError GAddress_INET_SetAnyAddress(GAddress *address)
+wxSocketError GAddress_INET_SetAnyAddress(GAddress *address)
 {
   return GAddress_INET_SetHostAddress(address, INADDR_ANY);
 }
 
-GSocketError GAddress_INET_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET_SetHostAddress(GAddress *address,
                                           unsigned long hostaddr)
 {
   struct in_addr *addr;
@@ -997,10 +670,10 @@ GSocketError GAddress_INET_SetHostAddress(GAddress *address,
   addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
   addr->s_addr = htonl(hostaddr);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
                                        const char *protocol)
 {
   struct servent *se;
@@ -1010,8 +683,8 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
 
   if (!port)
   {
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   se = getservbyname(port, protocol);
@@ -1024,20 +697,20 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
       port_int = atoi(port);
       addr = (struct sockaddr_in *)address->m_addr;
       addr->sin_port = htons((u_short) port_int);
-      return GSOCK_NOERROR;
+      return wxSOCKET_NOERROR;
     }
 
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   addr = (struct sockaddr_in *)address->m_addr;
   addr->sin_port = se->s_port;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
+wxSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
 {
   struct sockaddr_in *addr;
 
@@ -1046,10 +719,10 @@ GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
   addr = (struct sockaddr_in *)address->m_addr;
   addr->sin_port = htons(port);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
+wxSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
 {
   struct hostent *he;
   char *addr_buf;
@@ -1063,13 +736,13 @@ GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t
   he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
   if (he == NULL)
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   strncpy(hostname, he->h_name, sbuf);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 unsigned long GAddress_INET_GetHostAddress(GAddress *address)
@@ -1106,27 +779,27 @@ unsigned short GAddress_INET_GetPort(GAddress *address)
     #pragma comment(lib,"ws2_32")
 #endif // __VISUALC__
 
-GSocketError _GAddress_Init_INET6(GAddress *address)
+wxSocketError _GAddress_Init_INET6(GAddress *address)
 {
   struct in6_addr any_address = IN6ADDR_ANY_INIT;
   address->m_len  = sizeof(struct sockaddr_in6);
   address->m_addr = (struct sockaddr *) malloc(address->m_len);
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
   memset(address->m_addr,0,address->m_len);
 
-  address->m_family = GSOCK_INET6;
+  address->m_family = wxSOCKET_INET6;
   address->m_realfamily = AF_INET6;
   ((struct sockaddr_in6 *)address->m_addr)->sin6_family = AF_INET6;
   ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = any_address;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
+wxSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
 {
   CHECK_ADDRESS(address, INET6);
 
@@ -1136,16 +809,16 @@ GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
   addrinfo * info = 0;
   if ( getaddrinfo( hostname, "0", & hints, & info ) || ! info )
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   memcpy( address->m_addr, info->ai_addr, info->ai_addrlen );
   freeaddrinfo( info );
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
+wxSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
 {
   CHECK_ADDRESS(address, INET6);
 
@@ -1153,17 +826,17 @@ GSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
   memset( & addr, 0, sizeof( addr ) );
   return GAddress_INET6_SetHostAddress(address, addr);
 }
-GSocketError GAddress_INET6_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET6_SetHostAddress(GAddress *address,
                                           struct in6_addr hostaddr)
 {
   CHECK_ADDRESS(address, INET6);
 
   ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = hostaddr;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
                                        const char *protocol)
 {
   struct servent *se;
@@ -1173,8 +846,8 @@ GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
 
   if (!port)
   {
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   se = getservbyname(port, protocol);
@@ -1187,20 +860,20 @@ GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
       port_int = atoi(port);
       addr = (struct sockaddr_in6 *)address->m_addr;
       addr->sin6_port = htons((u_short) port_int);
-      return GSOCK_NOERROR;
+      return wxSOCKET_NOERROR;
     }
 
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   addr = (struct sockaddr_in6 *)address->m_addr;
   addr->sin6_port = se->s_port;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
+wxSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
 {
   struct sockaddr_in6 *addr;
 
@@ -1209,10 +882,10 @@ GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
   addr = (struct sockaddr_in6 *)address->m_addr;
   addr->sin6_port = htons(port);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
+wxSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
 {
   struct hostent *he;
   char *addr_buf;
@@ -1226,20 +899,20 @@ GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_
   he = gethostbyaddr(addr_buf, sizeof(addr->sin6_addr), AF_INET6);
   if (he == NULL)
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   strncpy(hostname, he->h_name, sbuf);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
+wxSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
 {
-  CHECK_ADDRESS_RETVAL(address, INET6, GSOCK_INVADDR);
+  CHECK_ADDRESS_RETVAL(address, INET6, wxSOCKET_INVADDR);
   *hostaddr = ( (struct sockaddr_in6 *)address->m_addr )->sin6_addr;
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 unsigned short GAddress_INET6_GetPort(GAddress *address)
@@ -1257,22 +930,22 @@ unsigned short GAddress_INET6_GetPort(GAddress *address)
  * -------------------------------------------------------------------------
  */
 
-GSocketError _GAddress_Init_UNIX(GAddress *address)
+wxSocketError _GAddress_Init_UNIX(GAddress *address)
 {
-  address->m_error = GSOCK_INVADDR;
-  return GSOCK_INVADDR;
+  address->m_error = wxSOCKET_INVADDR;
+  return wxSOCKET_INVADDR;
 }
 
-GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *WXUNUSED(path))
+wxSocketError GAddress_UNIX_SetPath(GAddress *address, const char *WXUNUSED(path))
 {
-  address->m_error = GSOCK_INVADDR;
-  return GSOCK_INVADDR;
+  address->m_error = wxSOCKET_INVADDR;
+  return wxSOCKET_INVADDR;
 }
 
-GSocketError GAddress_UNIX_GetPath(GAddress *address, char *WXUNUSED(path), size_t WXUNUSED(sbuf))
+wxSocketError GAddress_UNIX_GetPath(GAddress *address, char *WXUNUSED(path), size_t WXUNUSED(sbuf))
 {
-  address->m_error = GSOCK_INVADDR;
-  return GSOCK_INVADDR;
+  address->m_error = wxSOCKET_INVADDR;
+  return wxSOCKET_INVADDR;
 }
 
 #endif  // wxUSE_SOCKETS
index 087c50e6c6ff1e2fc0aa0613cf57a6ed0ee5702c..69ced421190c05f9dc9e196e6061bf325c0b8e3f 100644 (file)
@@ -1,13 +1,15 @@
-/* -------------------------------------------------------------------------
- * Project:     GSocket (Generic Socket)
- * Name:        src/msw/gsockmsw.cpp
- * Copyright:   (c) Guilhem Lavaux
- * Licence:     wxWindows Licence
- * Author:      Guillermo Rodriguez Garcia <guille@iies.es>
- * Purpose:     GSocket GUI-specific MSW code
- * CVSID:       $Id$
- * -------------------------------------------------------------------------
- */
+/////////////////////////////////////////////////////////////////////////////
+// Name:       src/msw/gsockmsw.cpp
+// Purpose:    MSW-specific socket support
+// Authors:    Guilhem Lavaux, Guillermo Rodriguez Garcia
+// Created:    April 1997
+// Copyright:  (C) 1999-1997, Guilhem Lavaux
+//             (C) 1999-2000, Guillermo Rodriguez Garcia
+//             (C) 2008 Vadim Zeitlin
+// RCS_ID:     $Id$
+// License:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
@@ -64,13 +66,13 @@ WX_DECLARE_HASH_MAP(int,bool,wxIntegerHash,wxIntegerEqual,SocketHash);
 #  pragma warning(default:4115) /* named type definition in parentheses */
 #endif
 
-#define CLASSNAME  TEXT("_GSocket_Internal_Window_Class")
+#define CLASSNAME  TEXT("_wxSocket_Internal_Window_Class")
 
 /* implemented in utils.cpp */
 extern "C" WXDLLIMPEXP_BASE HWND
 wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc);
 
-/* Maximum number of different GSocket objects at a given time.
+/* Maximum number of different wxSocket objects at a given time.
  * This value can be modified at will, but it CANNOT be greater
  * than (0x7FFF - WM_USER + 1)
  */
@@ -95,13 +97,13 @@ typedef int (PASCAL *WSAWaitForMultipleEventsFunc)(long,HANDLE,BOOL,long,BOOL);
 typedef int (PASCAL *WSAEnumNetworkEventsFunc)(SOCKET,HANDLE,LPWSANETWORKEVENTS);
 #endif //__WXWINCE__
 
-LRESULT CALLBACK _GSocket_Internal_WinProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK wxSocket_Internal_WinProc(HWND, UINT, WPARAM, LPARAM);
 
 /* Global variables */
 
 static HWND hWin;
 static CRITICAL_SECTION critical;
-static GSocket* socketList[MAXSOCKETS];
+static wxSocketImplMSW *socketList[MAXSOCKETS];
 static int firstAvailable;
 
 #ifndef __WXWINCE__
@@ -175,32 +177,32 @@ DWORD WINAPI SocketThread(LPVOID data)
 #endif
 
 // ----------------------------------------------------------------------------
-// MSW implementation of GSocketManager
+// MSW implementation of wxSocketManager
 // ----------------------------------------------------------------------------
 
-class GSocketMSWManager : public GSocketManager
+class wxSocketMSWManager : public wxSocketManager
 {
 public:
     virtual bool OnInit();
     virtual void OnExit();
 
-    virtual bool Init_Socket(GSocket *socket);
-    virtual void Close_Socket(GSocket *socket);
-    virtual void Destroy_Socket(GSocket *socket);
-
-    virtual void Install_Callback(GSocket *socket, GSocketEvent event);
-    virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
+    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
+    {
+        return new wxSocketImplMSW(wxsocket);
+    }
+    virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
+    virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
 };
 
 /* Global initializers */
 
-bool GSocketMSWManager::OnInit()
+bool wxSocketMSWManager::OnInit()
 {
   static LPCTSTR pclassname = NULL;
   int i;
 
   /* Create internal window for event notifications */
-  hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, _GSocket_Internal_WinProc);
+  hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, wxSocket_Internal_WinProc);
   if (!hWin)
       return false;
 
@@ -253,10 +255,12 @@ bool GSocketMSWManager::OnInit()
   currSocket = 0;
 #endif
 
-  return true;
+  // finally initialize WinSock
+  WSADATA wsaData;
+  return WSAStartup((1 << 8) | 1, &wsaData) == 0;
 }
 
-void GSocketMSWManager::OnExit()
+void wxSocketMSWManager::OnExit()
 {
 #ifdef __WXWINCE__
 /* Delete the threads here */
@@ -276,18 +280,19 @@ void GSocketMSWManager::OnExit()
 
   /* Delete critical section */
   DeleteCriticalSection(&critical);
+
+  WSACleanup();
 }
 
 /* Per-socket GUI initialization / cleanup */
 
-bool GSocketMSWManager::Init_Socket(GSocket *socket)
+wxSocketImplMSW::wxSocketImplMSW(wxSocketBase& wxsocket)
+    : wxSocketImpl(wxsocket)
 {
-  int i;
-
   /* Allocate a new message number for this socket */
   EnterCriticalSection(&critical);
 
-  i = firstAvailable;
+  int i = firstAvailable;
   while (socketList[i] != NULL)
   {
     i = (i + 1) % MAXSOCKETS;
@@ -295,41 +300,32 @@ bool GSocketMSWManager::Init_Socket(GSocket *socket)
     if (i == firstAvailable)    /* abort! */
     {
       LeaveCriticalSection(&critical);
-      return false;
+      m_msgnumber = 0; // invalid
+      return;
     }
   }
-  socketList[i] = socket;
+  socketList[i] = this;
   firstAvailable = (i + 1) % MAXSOCKETS;
-  socket->m_msgnumber = (i + WM_USER);
+  m_msgnumber = (i + WM_USER);
 
   LeaveCriticalSection(&critical);
-
-  return true;
-}
-
-void GSocketMSWManager::Close_Socket(GSocket *socket)
-{
-    Uninstall_Callback(socket, GSOCK_MAX_EVENT /* unused anyhow */);
-
-    closesocket(socket->m_fd);
 }
 
-void GSocketMSWManager::Destroy_Socket(GSocket *socket)
+wxSocketImplMSW::~wxSocketImplMSW()
 {
   /* Remove the socket from the list */
   EnterCriticalSection(&critical);
 
-  const int msgnum = socket->m_msgnumber;
-  if ( msgnum )
+  if ( m_msgnumber )
   {
       // we need to remove any pending messages for this socket to avoid having
       // them sent to a new socket which could reuse the same message number as
       // soon as we destroy this one
       MSG msg;
-      while ( ::PeekMessage(&msg, hWin, msgnum, msgnum, PM_REMOVE) )
+      while ( ::PeekMessage(&msg, hWin, m_msgnumber, m_msgnumber, PM_REMOVE) )
           ;
 
-      socketList[msgnum - WM_USER] = NULL;
+      socketList[m_msgnumber - WM_USER] = NULL;
   }
   //else: the socket has never been created successfully
 
@@ -338,19 +334,19 @@ void GSocketMSWManager::Destroy_Socket(GSocket *socket)
 
 /* Windows proc for asynchronous event handling */
 
-LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
+LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd,
                                            UINT uMsg,
                                            WPARAM wParam,
                                            LPARAM lParam)
 {
-  GSocket *socket;
-  GSocketEvent event;
+  wxSocketImplMSW *socket;
+  wxSocketNotify event;
 
   if (uMsg >= WM_USER && uMsg <= (WM_USER + MAXSOCKETS - 1))
   {
     EnterCriticalSection(&critical);
     socket = socketList[(uMsg - WM_USER)];
-    event = (GSocketEvent) -1;
+    event = (wxSocketNotify) -1;
 
     /* Check that the socket still exists (it has not been
      * destroyed) and for safety, check that the m_fd field
@@ -360,24 +356,24 @@ LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
     {
       switch WSAGETSELECTEVENT(lParam)
       {
-        case FD_READ:    event = GSOCK_INPUT; break;
-        case FD_WRITE:   event = GSOCK_OUTPUT; break;
-        case FD_ACCEPT:  event = GSOCK_CONNECTION; break;
+        case FD_READ:    event = wxSOCKET_INPUT; break;
+        case FD_WRITE:   event = wxSOCKET_OUTPUT; break;
+        case FD_ACCEPT:  event = wxSOCKET_CONNECTION; break;
         case FD_CONNECT:
         {
           if (WSAGETSELECTERROR(lParam) != 0)
-            event = GSOCK_LOST;
+            event = wxSOCKET_LOST;
           else
-            event = GSOCK_CONNECTION;
+            event = wxSOCKET_CONNECTION;
           break;
         }
-        case FD_CLOSE:   event = GSOCK_LOST; break;
+        case FD_CLOSE:   event = wxSOCKET_LOST; break;
       }
 
       if (event != -1)
       {
-        if (event == GSOCK_LOST)
-          socket->m_detected = GSOCK_LOST_FLAG;
+        if (event == wxSOCKET_LOST)
+          socket->m_detected = wxSOCKET_LOST_FLAG;
         else
           socket->m_detected |= (1 << event);
       }
@@ -399,9 +395,11 @@ LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
  *  events for internal processing, but we will only notify users
  *  when an appropriate callback function has been installed.
  */
-void GSocketMSWManager::Install_Callback(GSocket *socket,
-                                         GSocketEvent WXUNUSED(event))
+void wxSocketMSWManager::Install_Callback(wxSocketImpl *socket_,
+                                         wxSocketNotify WXUNUSED(event))
 {
+    wxSocketImplMSW * const socket = static_cast<wxSocketImplMSW *>(socket_);
+
   if (socket->m_fd != INVALID_SOCKET)
   {
     /* We could probably just subscribe to all events regardless
@@ -431,9 +429,11 @@ void GSocketMSWManager::Install_Callback(GSocket *socket,
 /*
  *  Disable event notifications (used when shutting down the socket)
  */
-void GSocketMSWManager::Uninstall_Callback(GSocket *socket,
-                                           GSocketEvent WXUNUSED(event))
+void wxSocketMSWManager::Uninstall_Callback(wxSocketImpl *socket_,
+                                           wxSocketNotify WXUNUSED(event))
 {
+    wxSocketImplMSW * const socket = static_cast<wxSocketImplMSW *>(socket_);
+
   if (socket->m_fd != INVALID_SOCKET)
   {
 #ifndef __WXWINCE__
@@ -445,15 +445,15 @@ void GSocketMSWManager::Uninstall_Callback(GSocket *socket,
   }
 }
 
-// set the wxBase variable to point to our GSocketManager implementation
+// set the wxBase variable to point to our wxSocketManager implementation
 //
-// see comments in wx/msw/apptbase.h for the explanation of why do we do it
+// see comments in wx/apptrait.h for the explanation of why do we do it
 // like this
 static struct ManagerSetter
 {
     ManagerSetter()
     {
-        static GSocketMSWManager s_manager;
+        static wxSocketMSWManager s_manager;
         wxAppTraits::SetDefaultSocketManager(&s_manager);
     }
 } gs_managerSetter;
index 841675297d6deaff8932b8c1ff40a0bd70432844..ec7d114d7eb5b5e8c5bff08e933738a7c897cda2 100644 (file)
@@ -1,7 +1,7 @@
 /* -------------------------------------------------------------------------
- * Project: GSocket (Generic Socket) for WX
+ * Project: wxSocketImpl (Generic Socket) for WX
  * Name:    gsockpm.c
- * Purpose: GSocket: PM part
+ * Purpose: wxSocketImpl: PM part
  * Licence: The wxWindows licence
  * CVSID:   $Id$
  * ------------------------------------------------------------------------- */
 #define wxSockReadMask  0x01
 #define wxSockWriteMask 0x02
 
-static void _GSocket_PM_Input(void *data)
+static void wxSocket_PM_Input(void *data)
 {
-    GSocket *socket = (GSocket *) data;
+    wxSocketImpl *socket = static_cast<wxSocketImpl *>(data);
+
     socket->Detected_Read();
 }
 
-static void _GSocket_PM_Output(void *data)
+static void wxSocket_PM_Output(void *data)
 {
-    GSocket *socket = (GSocket *) data;
+    wxSocketImpl *socket = static_cast<wxSocketImpl *>(data);
+
     socket->Detected_Write();
 }
 
-class PMSocketManager : public GSocketInputBasedManager
+class PMSocketManager : public wxSocketInputBasedManager
 {
 public:
-    virtual int AddInput(GSocket *socket, SocketDir d)
+    virtual int AddInput(wxSocketImpl *socket, SocketDir d)
     {
 
       if (d == FD_OUTPUT)
           return wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
-                                           _GSocket_PM_Output, (void *)socket);
+                                            wxSocket_PM_Output, (void *)socket);
       else
           return wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
-                                         _GSocket_PM_Input, (void *)socket);
+                                            wxSocket_PM_Input, (void *)socket);
     }
 
     virtual void RemoveInput(int fd)
@@ -51,7 +53,7 @@ public:
     }
 };
 
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
 {
     static PMSocketManager s_manager;
     return &s_manager;
index 38bc5b1da899fb5d86ca548b213f8c1a4a6480b9..d443e4b54ff63caaea203542a0fe3c78ed79c530 100644 (file)
@@ -1,16 +1,20 @@
-/* -------------------------------------------------------------------------
- * Project: GSocket (Generic Socket) for WX
- * Name:    src/osx/corefoundation/gsockosx.c
- * Purpose: GSocket: Mac OS X mach-o part
- * CVSID:   $Id$
- * Mac code by Brian Victor, February 2002.  Email comments to bhv1@psu.edu
- * ------------------------------------------------------------------------- */
+/////////////////////////////////////////////////////////////////////////////
+// Name:        osx/core/gsockosx.cpp
+// Purpose:     wxSocketImpl implementation for OS X
+// Authors:     Brian Victor, Vadim Zeitlin
+// Created:     February 2002
+// RCS-ID:      $Id$
+// Copyright:   (c) 2002 Brian Victor
+//              (c) 2008 Vadim Zeitlin
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
 
 #if wxUSE_SOCKETS
 
 #include "wx/private/gsocket.h"
+#include "wx/unix/gsockunx.h"
 #include "wx/apptrait.h"
 
 #include <CoreFoundation/CoreFoundation.h>
@@ -27,32 +31,63 @@ namespace
 static CFRunLoopRef gs_mainRunLoop = NULL;
 
 // ----------------------------------------------------------------------------
-// Mac-specific data associated with each socket by GSocketCFManager
+// Mac-specific socket implementation
 // ----------------------------------------------------------------------------
 
-class MacGSocketData
+class wxSocketImplMac : public wxSocketImplUnix
 {
 public:
-    // default ctor creates the object in uninitialized state, use Initialize()
-    // later to make it usable
-    MacGSocketData()
+    wxSocketImplMac(wxSocketBase& wxsocket)
+        : wxSocketImplUnix(wxsocket)
     {
         m_socket = NULL;
         m_source = NULL;
     }
 
-    // initialize the data associated with the given socket
-    bool Initialize(GSocket *socket)
+    virtual ~wxSocketImplMac()
+    {
+        wxASSERT_MSG( !m_source && !m_socket, "forgot to call Close()?" );
+    }
+
+    // get the underlying socket: creates it on demand
+    CFSocketRef GetSocket() /* const */
+    {
+        if ( !m_socket )
+            Initialize();
+
+        return m_socket;
+    }
+
+private:
+    virtual void DoClose()
     {
-        wxASSERT_MSG( !IsInitialized(), "shouldn't be called twice" );
+        wxSocketManager * const manager = wxSocketManager::Get();
+        if ( manager )
+        {
+            manager->Uninstall_Callback(this, wxSOCKET_INPUT);
+            manager->Uninstall_Callback(this, wxSOCKET_OUTPUT);
+        }
+
+        // VZ: CFRunLoopRemoveSource() is probably unnecessary as
+        //     CFSocketInvalidate() seems to do it internally from reading the
+        //     docs, please remove it (and this comment) after testing
+        CFRunLoopRemoveSource(gs_mainRunLoop, m_source, kCFRunLoopCommonModes);
+        CFSocketInvalidate(m_socket);
 
+        CFRelease(m_source);
+        CFRelease(m_socket);
+    }
+
+    // initialize the data associated with the given socket
+    bool Initialize()
+    {
         // we need a valid Unix socket to create a CFSocket
-        if ( socket->m_fd < 0 )
+        if ( m_fd < 0 )
             return false;
 
         CFSocketContext cont;
         cont.version = 0;               // this currently must be 0
-        cont.info = socket;             // pointer passed to our callback
+        cont.info = this;               // pointer passed to our callback
         cont.retain = NULL;             // no need to retain/release/copy the
         cont.release = NULL;            //  socket pointer, so all callbacks
         cont.copyDescription = NULL;    //  can be left NULL
@@ -60,7 +95,7 @@ public:
         m_socket = CFSocketCreateWithNative
                    (
                         NULL,                   // default allocator
-                        socket->m_fd,
+                        m_fd,
                         kCFSocketReadCallBack |
                         kCFSocketWriteCallBack |
                         kCFSocketConnectCallBack,
@@ -83,55 +118,13 @@ public:
         return true;
     }
 
-    // close the socket if it was opened
-    void Close()
-    {
-        // VZ: CFRunLoopRemoveSource() is probably unnecessary as
-        //     CFSocketInvalidate() seems to do it internally from reading the
-        //     docs, please remove it (and this comment) after testing
-        CFRunLoopRemoveSource(gs_mainRunLoop, m_source, kCFRunLoopCommonModes);
-        CFSocketInvalidate(m_socket);
-
-        CFRelease(m_source);
-        CFRelease(m_socket);
-    }
-
-    ~MacGSocketData()
-    {
-        wxASSERT_MSG( !m_source && !m_socket, "forgot to call Close()?" );
-    }
-
-    // return true if Initialize() had already been called successfully
-    bool IsInitialized() const { return m_source && m_socket; }
-
-
-    // accessors: should only be called if IsInitialized()
-    CFSocketRef GetSocket() const
-    {
-        wxASSERT( IsInitialized() );
-
-        return m_socket;
-    }
-
-    CFRunLoopSourceRef GetSource() const
-    {
-        wxASSERT( IsInitialized() );
-
-        return m_source;
-    }
-
-private:
     static void SocketCallback(CFSocketRef WXUNUSED(s),
                                CFSocketCallBackType callbackType,
                                CFDataRef WXUNUSED(address),
                                const void* data,
                                void* info)
     {
-        GSocket * const socket = static_cast<GSocket *>(info);
-        MacGSocketData * const
-            macdata = static_cast<MacGSocketData *>(socket->m_gui_dependent);
-        if ( !macdata )
-            return;
+        wxSocketImplMac * const socket = static_cast<wxSocketImplMac *>(info);
 
         switch (callbackType)
         {
@@ -163,66 +156,39 @@ private:
     CFSocketRef m_socket;
     CFRunLoopSourceRef m_source;
 
-    DECLARE_NO_COPY_CLASS(MacGSocketData);
+    DECLARE_NO_COPY_CLASS(wxSocketImplMac)
 };
 
 } // anonymous namespace
 
 
 // ----------------------------------------------------------------------------
-// CoreFoundation implementation of GSocketManager
+// CoreFoundation implementation of wxSocketManager
 // ----------------------------------------------------------------------------
 
-class GSocketCFManager : public GSocketManager
+class wxSocketManagerMac : public wxSocketManager
 {
 public:
     virtual bool OnInit();
     virtual void OnExit();
 
-    virtual bool Init_Socket(GSocket *socket);
-    virtual void Close_Socket(GSocket *socket);
-    virtual void Destroy_Socket(GSocket *socket);
-
-    virtual void Install_Callback(GSocket *socket, GSocketEvent event);
-    virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
-
-private:
-    // retrieve our custom data associated with the given socket
-    //
-    // this is a low level function, use GetInitializedData() instead if the
-    // data pointer should also be correctly initialized if it hadn't been done
-    // yet
-    //
-    // may return NULL if we hadn't created the data for this socket yet
-    MacGSocketData *GetData(GSocket *socket) const
+    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
     {
-        return static_cast<MacGSocketData *>(socket->m_gui_dependent);
+        return new wxSocketImplMac(wxsocket);
     }
 
-    // return the custom data pointer initializing it if it hadn't been done
-    // yet
-    //
-    // may return NULL if there is no associated data
-    MacGSocketData *GetInitializedData(GSocket *socket) const
-    {
-        MacGSocketData * const data = GetData(socket);
-        if ( data && !data->IsInitialized() )
-        {
-            if ( !data->Initialize(socket) )
-                return NULL;
-        }
-
-        return data;
-    }
+    virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
+    virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
 
+private:
     // return CFSocket callback mask corresponding to the given event (the
     // socket parameter is needed because some events are interpreted
     // differently depending on whether they happen on a server or on a client
     // socket)
-    static int GetCFCallback(GSocket *socket, GSocketEvent event);
+    static int GetCFCallback(wxSocketImpl *socket, wxSocketNotify event);
 };
 
-bool GSocketCFManager::OnInit()
+bool wxSocketManagerMac::OnInit()
 {
     // No need to store the main loop again
     if (gs_mainRunLoop != NULL)
@@ -240,88 +206,66 @@ bool GSocketCFManager::OnInit()
     return true;
 }
 
-void GSocketCFManager::OnExit()
+void wxSocketManagerMac::OnExit()
 {
     // Release the reference count, and set the reference back to NULL
     CFRelease(gs_mainRunLoop);
     gs_mainRunLoop = NULL;
 }
 
-bool GSocketCFManager::Init_Socket(GSocket *socket)
-{
-    socket->m_gui_dependent = new MacGSocketData;
-    return true;
-}
-
-void GSocketCFManager::Close_Socket(GSocket *socket)
-{
-    Uninstall_Callback(socket, GSOCK_INPUT);
-    Uninstall_Callback(socket, GSOCK_OUTPUT);
-
-    MacGSocketData * const data = GetData(socket);
-    if ( data )
-        data->Close();
-}
-
-void GSocketCFManager::Destroy_Socket(GSocket *socket)
-{
-    MacGSocketData * const data = GetData(socket);
-    if ( data )
-    {
-        delete data;
-        socket->m_gui_dependent = NULL;
-    }
-}
-
 /* static */
-int GSocketCFManager::GetCFCallback(GSocket *socket, GSocketEvent event)
+int wxSocketManagerMac::GetCFCallback(wxSocketImpl *socket, wxSocketNotify event)
 {
     switch ( event )
     {
-        case GSOCK_CONNECTION:
+        case wxSOCKET_CONNECTION:
             return socket->m_server ? kCFSocketReadCallBack
                                     : kCFSocketConnectCallBack;
 
-        case GSOCK_LOST:
-        case GSOCK_INPUT:
+        case wxSOCKET_LOST:
+        case wxSOCKET_INPUT:
             return kCFSocketReadCallBack;
 
-        case GSOCK_OUTPUT:
+        case wxSOCKET_OUTPUT:
             return kCFSocketWriteCallBack;
 
-        case GSOCK_MAX_EVENT:
-            wxFAIL_MSG( "invalid GSocketEvent" );
+        case wxSOCKET_MAX_EVENT:
+            wxFAIL_MSG( "invalid wxSocketNotify" );
             return 0;
 
         default:
-            wxFAIL_MSG( "unknown GSocketEvent" );
+            wxFAIL_MSG( "unknown wxSocketNotify" );
             return 0;
     }
 }
 
-void GSocketCFManager::Install_Callback(GSocket *socket, GSocketEvent event)
+void wxSocketManagerMac::Install_Callback(wxSocketImpl *socket_,
+                                          wxSocketNotify event)
 {
-    const MacGSocketData * const data = GetInitializedData(socket);
-    if ( !data )
-        return;
+    wxSocketImplMac * const socket = static_cast<wxSocketImplMac *>(socket_);
 
-    CFSocketEnableCallBacks(data->GetSocket(), GetCFCallback(socket, event));
+    CFSocketEnableCallBacks(socket->GetSocket(), GetCFCallback(socket, event));
 }
 
-void GSocketCFManager::Uninstall_Callback(GSocket *socket, GSocketEvent event)
+void wxSocketManagerMac::Uninstall_Callback(wxSocketImpl *socket_,
+                                            wxSocketNotify event)
 {
-    const MacGSocketData * const data = GetInitializedData(socket);
-    if ( !data )
-        return;
+    wxSocketImplMac * const socket = static_cast<wxSocketImplMac *>(socket_);
 
-    CFSocketDisableCallBacks(data->GetSocket(), GetCFCallback(socket, event));
+    CFSocketDisableCallBacks(socket->GetSocket(), GetCFCallback(socket, event));
 }
 
-GSocketManager *wxAppTraits::GetSocketManager()
+// set the wxBase variable to point to our wxSocketManager implementation
+//
+// see comments in wx/apptrait.h for the explanation of why do we do it
+// like this
+static struct ManagerSetter
 {
-    static GSocketCFManager s_manager;
-
-    return &s_manager;
-};
+    ManagerSetter()
+    {
+        static wxSocketManagerMac s_manager;
+        wxAppTraits::SetDefaultSocketManager(&s_manager);
+    }
+} gs_managerSetter;
 
 #endif // wxUSE_SOCKETS
index fdda9ab84360f01fb0304f3538a0bd8a19dc6ebc..2bdfa8d43b1583f02151ef640dfa1385d12cda2f 100644 (file)
@@ -1,16 +1,15 @@
-/* -------------------------------------------------------------------------
- * Project:     GSocket (Generic Socket) for WX
- * Name:        gsocket.c
- * Copyright:   (c) Guilhem Lavaux
- * Licence:     wxWindows Licence
- * Authors:     David Elliott (C++ conversion, maintainer)
- *              Guilhem Lavaux,
- *              Guillermo Rodriguez Garcia <guille@iies.es>
- * Purpose:     GSocket main Unix and OS/2 file
- * Licence:     The wxWindows licence
- * CVSID:       $Id$
- * -------------------------------------------------------------------------
- */
+/////////////////////////////////////////////////////////////////////////////
+// Name:        src/unix/gsocket.cpp
+// Purpose:     wxSocketImpl implementation for Unix systems
+// Authors:     Guilhem Lavaux, Guillermo Rodriguez Garcia, David Elliott,
+//              Vadim Zeitlin
+// Created:     April 1997
+// RCS-ID:      $Id$
+// Copyright:   (c) 1997 Guilhem Lavaux
+//              (c) 2008 Vadim Zeitlin
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
 
 #include "wx/wxprec.h"
 
@@ -429,194 +428,89 @@ struct servent *wxGetservbyname_r(const char *port, const char *protocol,
 
 /* debugging helpers */
 #ifdef __GSOCKET_DEBUG__
-#  define GSocket_Debug(args) printf args
+#  define SOCKET_DEBUG(args) printf args
 #else
-#  define GSocket_Debug(args)
+#  define SOCKET_DEBUG(args)
 #endif /* __GSOCKET_DEBUG__ */
 
-/* Table of GUI-related functions. We must call them indirectly because
- * of wxBase and GUI separation: */
+/* Constructors / Destructors for wxSocketImplUnix */
 
-bool GSocket_Init()
+wxSocketImplUnix::wxSocketImplUnix(wxSocketBase& wxsocket)
+    : wxSocketImpl(wxsocket)
 {
-    GSocketManager * const manager = GSocketManager::Get();
-    return manager && manager->OnInit();
-}
+    m_fds[0] =
+    m_fds[1] = -1;
 
-void GSocket_Cleanup()
-{
-    GSocketManager * const manager = GSocketManager::Get();
-    if ( manager )
-        manager->OnExit();
+    m_use_events = false;
 }
 
-/* Constructors / Destructors for GSocket */
-
-GSocket::GSocket(wxSocketBase& wxsocket)
-       : GSocketBase(wxsocket)
-{
-  m_handler             = NULL;
-
-  m_gui_dependent       = NULL;
-  m_use_events          = false;
-}
-
-GSocket::~GSocket()
-{
-  delete m_handler;
-}
-
-/* GSocket_Shutdown:
+/*
  *  Disallow further read/write operations on this socket, close
  *  the fd and disable all callbacks.
  */
-void GSocket::Shutdown()
+void wxSocketImplUnix::Shutdown()
 {
     /* Don't allow events to fire after socket has been closed */
     DisableEvents();
 
-    GSocketBase::Shutdown();
+    wxSocketImpl::Shutdown();
 }
 
-/* Server specific parts */
-
-/* GSocket_SetServer:
- *  Sets up this socket as a server. The local address must have been
- *  set with GSocket_SetLocal() before GSocket_SetServer() is called.
- *  Returns GSOCK_NOERROR on success, one of the following otherwise:
- *
- *  Error codes:
- *    GSOCK_INVSOCK - the socket is in use.
- *    GSOCK_INVADDR - the local address has not been set.
- *    GSOCK_IOERR   - low-level error.
- */
-GSocketError GSocket::SetServer()
-{
-  int arg = 1;
-
-  assert(this);
-
-  /* must not be in use */
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  /* the local addr must have been set */
-  if (!m_local)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Initialize all fields */
-  m_stream   = true;
-  m_server   = true;
-
-  /* Create the socket */
-  m_fd = socket(m_local->m_realfamily, SOCK_STREAM, 0);
-
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
-#ifdef SO_NOSIGPIPE
-  setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(arg));
-#endif
-
-  ioctl(m_fd, FIONBIO, &arg);
-  EnableEvents();
-
-  /* allow a socket to re-bind if the socket is in the TIME_WAIT
-     state after being previously closed.
-   */
-  if (m_reusable)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-#ifdef SO_REUSEPORT
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
-#endif
-  }
-
-  /* Bind to the local address,
-   * retrieve the actual address bound,
-   * and listen up to 5 connections.
-   */
-  if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
-      (getsockname(m_fd,
-                   m_local->m_addr,
-                   (WX_SOCKLEN_T *) &m_local->m_len) != 0) ||
-      (listen(m_fd, 5) != 0))
-  {
-    Close();
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  return GSOCK_NOERROR;
-}
-
-/* GSocket_WaitConnection:
+/*
  *  Waits for an incoming client connection. Returns a pointer to
- *  a GSocket object, or NULL if there was an error, in which case
- *  the last error field will be updated for the calling GSocket.
+ *  a wxSocketImplUnix object, or NULL if there was an error, in which case
+ *  the last error field will be updated for the calling wxSocketImplUnix.
  *
- *  Error codes (set in the calling GSocket)
- *    GSOCK_INVSOCK    - the socket is not valid or not a server.
- *    GSOCK_TIMEDOUT   - timeout, no incoming connections.
- *    GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
- *    GSOCK_MEMERR     - couldn't allocate memory.
- *    GSOCK_IOERR      - low-level error.
+ *  Error codes (set in the calling wxSocketImplUnix)
+ *    wxSOCKET_INVSOCK    - the socket is not valid or not a server.
+ *    wxSOCKET_TIMEDOUT   - timeout, no incoming connections.
+ *    wxSOCKET_WOULDBLOCK - the call would block and the socket is nonblocking.
+ *    wxSOCKET_MEMERR     - couldn't allocate memory.
+ *    wxSOCKET_IOERR      - low-level error.
  */
-GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
+wxSocketImpl *wxSocketImplUnix::WaitConnection(wxSocketBase& wxsocket)
 {
   wxSockAddr from;
   WX_SOCKLEN_T fromlen = sizeof(from);
-  GSocket *connection;
-  GSocketError err;
+  wxSocketImpl *connection;
+  wxSocketError err;
   int arg = 1;
 
-  assert(this);
-
   /* If the socket has already been created, we exit immediately */
   if (m_fd == INVALID_SOCKET || !m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return NULL;
   }
 
-  /* Create a GSocket object for the new connection */
-  connection = GSocket::Create(wxsocket);
+  /* Create a wxSocketImplUnix object for the new connection */
+  connection = wxSocketImplUnix::Create(wxsocket);
 
   if (!connection)
   {
-    m_error = GSOCK_MEMERR;
+    m_error = wxSOCKET_MEMERR;
     return NULL;
   }
 
   /* Wait for a connection (with timeout) */
-  if (Input_Timeout() == GSOCK_TIMEDOUT)
+  if (Input_Timeout() == wxSOCKET_TIMEDOUT)
   {
     delete connection;
-    /* m_error set by _GSocket_Input_Timeout */
+    /* m_error set by Input_Timeout */
     return NULL;
   }
 
   connection->m_fd = accept(m_fd, (sockaddr*)&from, (WX_SOCKLEN_T *) &fromlen);
 
   /* Reenable CONNECTION events */
-  EnableEvent(GSOCK_CONNECTION);
+  EnableEvent(wxSOCKET_CONNECTION);
 
   if (connection->m_fd == INVALID_SOCKET)
   {
     if (errno == EWOULDBLOCK)
-      m_error = GSOCK_WOULDBLOCK;
+      m_error = wxSOCKET_WOULDBLOCK;
     else
-      m_error = GSOCK_IOERR;
+      m_error = wxSOCKET_IOERR;
 
     delete connection;
     return NULL;
@@ -631,12 +525,12 @@ GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
   if (!connection->m_peer)
   {
     delete connection;
-    m_error = GSOCK_MEMERR;
+    m_error = wxSOCKET_MEMERR;
     return NULL;
   }
 
   err = _GAddress_translate_from(connection->m_peer, (sockaddr*)&from, fromlen);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     delete connection;
     m_error = err;
@@ -654,7 +548,7 @@ GSocket *GSocket::WaitConnection(wxSocketBase& wxsocket)
   return connection;
 }
 
-void GSocket::Notify(bool flag)
+void wxSocketImplUnix::Notify(bool flag)
 {
     if (flag == m_use_events)
         return;
@@ -662,150 +556,23 @@ void GSocket::Notify(bool flag)
     DoEnableEvents(flag);
 }
 
-void GSocket::DoEnableEvents(bool flag)
+void wxSocketImplUnix::DoEnableEvents(bool flag)
 {
-    GSocketManager * const manager = GSocketManager::Get();
+    wxSocketManager * const manager = wxSocketManager::Get();
     if ( flag )
     {
-        manager->Install_Callback(this, GSOCK_INPUT);
-        manager->Install_Callback(this, GSOCK_OUTPUT);
+        manager->Install_Callback(this, wxSOCKET_INPUT);
+        manager->Install_Callback(this, wxSOCKET_OUTPUT);
     }
     else // off
     {
-        manager->Uninstall_Callback(this, GSOCK_INPUT);
-        manager->Uninstall_Callback(this, GSOCK_OUTPUT);
-    }
-}
-
-bool GSocket::SetReusable()
-{
-    /* socket must not be null, and must not be in use/already bound */
-    if (this && m_fd == INVALID_SOCKET)
-    {
-        m_reusable = true;
-
-        return true;
-    }
-
-    return false;
-}
-
-bool GSocket::SetBroadcast()
-{
-    /* socket must not be in use/already bound */
-    if (m_fd == INVALID_SOCKET) {
-        m_broadcast = true;
-        return true;
-    }
-    return false;
-}
-
-bool GSocket::DontDoBind()
-{
-    /* socket must not be in use/already bound */
-    if (m_fd == INVALID_SOCKET) {
-        m_dobind = false;
-        return true;
+        manager->Uninstall_Callback(this, wxSOCKET_INPUT);
+        manager->Uninstall_Callback(this, wxSOCKET_OUTPUT);
     }
-    return false;
 }
 
-/* Client specific parts */
-
-/* GSocket_Connect:
- *  For stream (connection oriented) sockets, GSocket_Connect() tries
- *  to establish a client connection to a server using the peer address
- *  as established with GSocket_SetPeer(). Returns GSOCK_NOERROR if the
- *  connection has been successfully established, or one of the error
- *  codes listed below. Note that for nonblocking sockets, a return
- *  value of GSOCK_WOULDBLOCK doesn't mean a failure. The connection
- *  request can be completed later; you should use GSocket_Select()
- *  to poll for GSOCK_CONNECTION | GSOCK_LOST, or wait for the
- *  corresponding asynchronous events.
- *
- *  For datagram (non connection oriented) sockets, GSocket_Connect()
- *  just sets the peer address established with GSocket_SetPeer() as
- *  default destination.
- *
- *  Error codes:
- *    GSOCK_INVSOCK    - the socket is in use or not valid.
- *    GSOCK_INVADDR    - the peer address has not been established.
- *    GSOCK_TIMEDOUT   - timeout, the connection failed.
- *    GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
- *    GSOCK_MEMERR     - couldn't allocate memory.
- *    GSOCK_IOERR      - low-level error.
- */
-GSocketError GSocket::Connect(GSocketStream stream)
+wxSocketError wxSocketImplUnix::DoHandleConnect(int ret)
 {
-  int err, ret;
-  int arg = 1;
-
-  assert(this);
-
-  /* Enable CONNECTION events (needed for nonblocking connections) */
-  EnableEvent(GSOCK_CONNECTION);
-
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  if (!m_peer)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Streamed or dgram socket? */
-  m_stream   = (stream == GSOCK_STREAMED);
-  m_server   = false;
-  m_establishing = false;
-
-  /* Create the socket */
-  m_fd = socket(m_peer->m_realfamily,
-                     m_stream? SOCK_STREAM : SOCK_DGRAM, 0);
-
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-
-  /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
-#ifdef SO_NOSIGPIPE
-  setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(arg));
-#endif
-
-#if defined(__EMX__) || defined(__VISAGECPP__)
-  ioctl(m_fd, FIONBIO, (char*)&arg, sizeof(arg));
-#else
-  ioctl(m_fd, FIONBIO, &arg);
-#endif
-
-  // If the reuse flag is set, use the applicable socket reuse flags(s)
-  if (m_reusable)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-#ifdef SO_REUSEPORT
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
-#endif
-  }
-
-  if (m_initialRecvBufferSize >= 0)
-    setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
-  if (m_initialSendBufferSize >= 0)
-    setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
-
-  // If a local address has been set, then we need to bind to it before calling connect
-  if (m_local && m_local->m_addr)
-  {
-     bind(m_fd, m_local->m_addr, m_local->m_len);
-  }
-
-  /* Connect it to the peer address, with a timeout (see below) */
-  ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
-
   /* We only call EnableEvents() if we know we aren't shutting down the socket.
    * NB: EnableEvents() needs to be called whether the socket is blocking or
    * non-blocking, it just shouldn't be called prior to knowing there is a
@@ -818,20 +585,20 @@ GSocketError GSocket::Connect(GSocketStream stream)
 
   if (ret == -1)
   {
-    err = errno;
+    const int err = errno;
 
-    /* If connect failed with EINPROGRESS and the GSocket object
+    /* If connect failed with EINPROGRESS and the wxSocketImplUnix object
      * is in blocking mode, we select() for the specified timeout
      * checking for writability to see if the connection request
      * completes.
      */
     if ((err == EINPROGRESS) && (!m_non_blocking))
     {
-      if (Output_Timeout() == GSOCK_TIMEDOUT)
+      if (Output_Timeout() == wxSOCKET_TIMEDOUT)
       {
         Close();
-        /* m_error is set in _GSocket_Output_Timeout */
-        return GSOCK_TIMEDOUT;
+        /* m_error is set in Output_Timeout */
+        return wxSOCKET_TIMEDOUT;
       }
       else
       {
@@ -842,136 +609,54 @@ GSocketError GSocket::Connect(GSocketStream stream)
         EnableEvents();
 
         if (!error)
-          return GSOCK_NOERROR;
+          return wxSOCKET_NOERROR;
       }
     }
 
-    /* If connect failed with EINPROGRESS and the GSocket object
-     * is set to nonblocking, we set m_error to GSOCK_WOULDBLOCK
-     * (and return GSOCK_WOULDBLOCK) but we don't close the socket;
-     * this way if the connection completes, a GSOCK_CONNECTION
+    /* If connect failed with EINPROGRESS and the wxSocketImplUnix object
+     * is set to nonblocking, we set m_error to wxSOCKET_WOULDBLOCK
+     * (and return wxSOCKET_WOULDBLOCK) but we don't close the socket;
+     * this way if the connection completes, a wxSOCKET_CONNECTION
      * event will be generated, if enabled.
      */
     if ((err == EINPROGRESS) && (m_non_blocking))
     {
       m_establishing = true;
-      m_error = GSOCK_WOULDBLOCK;
-      return GSOCK_WOULDBLOCK;
+      m_error = wxSOCKET_WOULDBLOCK;
+      return wxSOCKET_WOULDBLOCK;
     }
 
     /* If connect failed with an error other than EINPROGRESS,
-     * then the call to GSocket_Connect has failed.
+     * then the call to Connect has failed.
      */
     Close();
-    m_error = GSOCK_IOERR;
-
-    return GSOCK_IOERR;
-  }
-
-  return GSOCK_NOERROR;
-}
-
-/* Datagram sockets */
-
-/* GSocket_SetNonOriented:
- *  Sets up this socket as a non-connection oriented (datagram) socket.
- *  Before using this function, the local address must have been set
- *  with GSocket_SetLocal(), or the call will fail. Returns GSOCK_NOERROR
- *  on success, or one of the following otherwise.
- *
- *  Error codes:
- *    GSOCK_INVSOCK - the socket is in use.
- *    GSOCK_INVADDR - the local address has not been set.
- *    GSOCK_IOERR   - low-level error.
- */
-GSocketError GSocket::SetNonOriented()
-{
-  int arg = 1;
-
-  assert(this);
-
-  if (m_fd != INVALID_SOCKET)
-  {
-    m_error = GSOCK_INVSOCK;
-    return GSOCK_INVSOCK;
-  }
-
-  if (!m_local)
-  {
-    m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
-  }
-
-  /* Initialize all fields */
-  m_stream   = false;
-  m_server   = false;
-
-  /* Create the socket */
-  m_fd = socket(m_local->m_realfamily, SOCK_DGRAM, 0);
+    m_error = wxSOCKET_IOERR;
 
-  if (m_fd == INVALID_SOCKET)
-  {
-    m_error = GSOCK_IOERR;
-    return GSOCK_IOERR;
-  }
-#if defined(__EMX__) || defined(__VISAGECPP__)
-  ioctl(m_fd, FIONBIO, (char*)&arg, sizeof(arg));
-#else
-  ioctl(m_fd, FIONBIO, &arg);
-#endif
-  EnableEvents();
-
-  if (m_reusable)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
-#ifdef SO_REUSEPORT
-    setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
-#endif
+    return wxSOCKET_IOERR;
   }
 
-  if (m_broadcast)
-  {
-    setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST, (const char*)&arg, sizeof(arg));
-  }
-  if (m_dobind)
-  {
-      /* Bind to the local address,
-       * and retrieve the actual address bound.
-       */
-      if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
-          (getsockname(m_fd,
-                       m_local->m_addr,
-                       (WX_SOCKLEN_T *) &m_local->m_len) != 0))
-      {
-        Close();
-        m_error = GSOCK_IOERR;
-        return GSOCK_IOERR;
-      }
-  }
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 /* Generic IO */
 
 /* Like recv(), send(), ... */
-int GSocket::Read(char *buffer, int size)
+int wxSocketImplUnix::Read(char *buffer, int size)
 {
   int ret;
 
-  assert(this);
-
   if (m_fd == INVALID_SOCKET || m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return -1;
   }
 
   /* Disable events during query of socket status */
-  DisableEvent(GSOCK_INPUT);
+  DisableEvent(wxSOCKET_INPUT);
 
   /* If the socket is blocking, wait for data (with a timeout) */
-  if (Input_Timeout() == GSOCK_TIMEDOUT) {
-    m_error = GSOCK_TIMEDOUT;
+  if (Input_Timeout() == wxSOCKET_TIMEDOUT) {
+    m_error = wxSOCKET_TIMEDOUT;
     /* Don't return here immediately, otherwise socket events would not be
      * re-enabled! */
     ret = -1;
@@ -998,7 +683,7 @@ int GSocket::Read(char *buffer, int size)
       /* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
       if (m_use_events)
       {
-        m_detected = GSOCK_LOST_FLAG;
+        m_detected = wxSOCKET_LOST_FLAG;
         Detected_Read();
         return 0;
       }
@@ -1006,39 +691,37 @@ int GSocket::Read(char *buffer, int size)
     else if (ret == -1)
     {
       if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
-        m_error = GSOCK_WOULDBLOCK;
+        m_error = wxSOCKET_WOULDBLOCK;
       else
-        m_error = GSOCK_IOERR;
+        m_error = wxSOCKET_IOERR;
     }
   }
 
   /* Enable events again now that we are done processing */
-  EnableEvent(GSOCK_INPUT);
+  EnableEvent(wxSOCKET_INPUT);
 
   return ret;
 }
 
-int GSocket::Write(const char *buffer, int size)
+int wxSocketImplUnix::Write(const char *buffer, int size)
 {
   int ret;
 
-  assert(this);
-
-  GSocket_Debug(( "GSocket_Write #1, size %d\n", size ));
+  SOCKET_DEBUG(( "Write #1, size %d\n", size ));
 
   if (m_fd == INVALID_SOCKET || m_server)
   {
-    m_error = GSOCK_INVSOCK;
+    m_error = wxSOCKET_INVSOCK;
     return -1;
   }
 
-  GSocket_Debug(( "GSocket_Write #2, size %d\n", size ));
+  SOCKET_DEBUG(( "Write #2, size %d\n", size ));
 
   /* If the socket is blocking, wait for writability (with a timeout) */
-  if (Output_Timeout() == GSOCK_TIMEDOUT)
+  if (Output_Timeout() == wxSOCKET_TIMEDOUT)
     return -1;
 
-  GSocket_Debug(( "GSocket_Write #3, size %d\n", size ));
+  SOCKET_DEBUG(( "Write #3, size %d\n", size ));
 
   /* Write the data */
   if (m_stream)
@@ -1046,19 +729,19 @@ int GSocket::Write(const char *buffer, int size)
   else
     ret = Send_Dgram(buffer, size);
 
-  GSocket_Debug(( "GSocket_Write #4, size %d\n", size ));
+  SOCKET_DEBUG(( "Write #4, size %d\n", size ));
 
   if (ret == -1)
   {
     if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
     {
-      m_error = GSOCK_WOULDBLOCK;
-      GSocket_Debug(( "GSocket_Write error WOULDBLOCK\n" ));
+      m_error = wxSOCKET_WOULDBLOCK;
+      SOCKET_DEBUG(( "Write error WOULDBLOCK\n" ));
     }
     else
     {
-      m_error = GSOCK_IOERR;
-      GSocket_Debug(( "GSocket_Write error IOERR\n" ));
+      m_error = wxSOCKET_IOERR;
+      SOCKET_DEBUG(( "Write error IOERR\n" ));
     }
 
     /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
@@ -1066,84 +749,41 @@ int GSocket::Write(const char *buffer, int size)
      * that the socket is writable until a read operation fails. Only then
      * will further OUTPUT events be posted.
      */
-    EnableEvent(GSOCK_OUTPUT);
+    EnableEvent(wxSOCKET_OUTPUT);
 
     return -1;
   }
 
-  GSocket_Debug(( "GSocket_Write #5, size %d ret %d\n", size, ret ));
+  SOCKET_DEBUG(( "Write #5, size %d ret %d\n", size, ret ));
 
   return ret;
 }
 
 /* Flags */
 
-/* GSocket_SetNonBlocking:
- *  Sets the socket to non-blocking mode. All IO calls will return
- *  immediately.
- */
-void GSocket::SetNonBlocking(bool non_block)
-{
-  assert(this);
-
-  GSocket_Debug( ("GSocket_SetNonBlocking: %d\n", (int)non_block) );
-
-  m_non_blocking = non_block;
-}
-
-/* GSocket_GetError:
- *  Returns the last error occurred for this socket. Note that successful
- *  operations do not clear this back to GSOCK_NOERROR, so use it only
- *  after an error.
- */
-GSocketError WXDLLIMPEXP_NET GSocket::GetError()
-{
-  assert(this);
-
-  return m_error;
-}
-
-GSocketError GSocket::GetSockOpt(int level, int optname,
-                                void *optval, int *optlen)
-{
-    if (getsockopt(m_fd, level, optname, (char*)optval, (SOCKOPTLEN_T*)optlen) == 0)
-        return GSOCK_NOERROR;
-
-    return GSOCK_OPTERR;
-}
-
-GSocketError GSocket::SetSockOpt(int level, int optname,
-                                const void *optval, int optlen)
-{
-    if (setsockopt(m_fd, level, optname, (const char*)optval, optlen) == 0)
-        return GSOCK_NOERROR;
-
-    return GSOCK_OPTERR;
-}
-
-void GSocket::EnableEvent(GSocketEvent event)
+void wxSocketImplUnix::EnableEvent(wxSocketNotify event)
 {
     if (m_use_events)
     {
         m_detected &= ~(1 << event);
-        GSocketManager::Get()->Install_Callback(this, event);
+        wxSocketManager::Get()->Install_Callback(this, event);
     }
 }
 
-void GSocket::DisableEvent(GSocketEvent event)
+void wxSocketImplUnix::DisableEvent(wxSocketNotify event)
 {
     if (m_use_events)
     {
         m_detected |= (1 << event);
-        GSocketManager::Get()->Uninstall_Callback(this, event);
+        wxSocketManager::Get()->Uninstall_Callback(this, event);
     }
 }
 
-/* _GSocket_Input_Timeout:
+/*
  *  For blocking sockets, wait until data is available or
  *  until timeout ellapses.
  */
-GSocketError GSocket::Input_Timeout()
+wxSocketError wxSocketImplUnix::Input_Timeout()
 {
   fd_set readfds;
   int ret;
@@ -1158,31 +798,31 @@ GSocketError GSocket::Input_Timeout()
     ret = select(m_fd + 1, &readfds, NULL, NULL, &tv);
     if (ret == 0)
     {
-      GSocket_Debug(( "GSocket_Input_Timeout, select returned 0\n" ));
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      SOCKET_DEBUG(( "Input_Timeout, select returned 0\n" ));
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
 
     if (ret == -1)
     {
-      GSocket_Debug(( "GSocket_Input_Timeout, select returned -1\n" ));
-      if (errno == EBADF) { GSocket_Debug(( "Invalid file descriptor\n" )); }
-      if (errno == EINTR) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
-      if (errno == EINVAL) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
-      if (errno == ENOMEM) { GSocket_Debug(( "Not enough memory\n" )); }
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      SOCKET_DEBUG(( "Input_Timeout, select returned -1\n" ));
+      if (errno == EBADF) { SOCKET_DEBUG(( "Invalid file descriptor\n" )); }
+      if (errno == EINTR) { SOCKET_DEBUG(( "A non blocked signal was caught\n" )); }
+      if (errno == EINVAL) { SOCKET_DEBUG(( "The highest number descriptor is negative\n" )); }
+      if (errno == ENOMEM) { SOCKET_DEBUG(( "Not enough memory\n" )); }
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
   }
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-/* _GSocket_Output_Timeout:
+/*
  *  For blocking sockets, wait until data can be sent without
  *  blocking or until timeout ellapses.
  */
-GSocketError GSocket::Output_Timeout()
+wxSocketError wxSocketImplUnix::Output_Timeout()
 {
   fd_set writefds;
   int ret;
@@ -1190,7 +830,7 @@ GSocketError GSocket::Output_Timeout()
   // Linux select() will overwrite the struct on return so make a copy
   struct timeval tv = m_timeout;
 
-  GSocket_Debug( ("m_non_blocking has: %d\n", (int)m_non_blocking) );
+  SOCKET_DEBUG( ("m_non_blocking has: %d\n", (int)m_non_blocking) );
 
   if (!m_non_blocking)
   {
@@ -1199,40 +839,40 @@ GSocketError GSocket::Output_Timeout()
     ret = select(m_fd + 1, NULL, &writefds, NULL, &tv);
     if (ret == 0)
     {
-      GSocket_Debug(( "GSocket_Output_Timeout, select returned 0\n" ));
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      SOCKET_DEBUG(( "Output_Timeout, select returned 0\n" ));
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
 
     if (ret == -1)
     {
-      GSocket_Debug(( "GSocket_Output_Timeout, select returned -1\n" ));
-      if (errno == EBADF) { GSocket_Debug(( "Invalid file descriptor\n" )); }
-      if (errno == EINTR) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
-      if (errno == EINVAL) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
-      if (errno == ENOMEM) { GSocket_Debug(( "Not enough memory\n" )); }
-      m_error = GSOCK_TIMEDOUT;
-      return GSOCK_TIMEDOUT;
+      SOCKET_DEBUG(( "Output_Timeout, select returned -1\n" ));
+      if (errno == EBADF) { SOCKET_DEBUG(( "Invalid file descriptor\n" )); }
+      if (errno == EINTR) { SOCKET_DEBUG(( "A non blocked signal was caught\n" )); }
+      if (errno == EINVAL) { SOCKET_DEBUG(( "The highest number descriptor is negative\n" )); }
+      if (errno == ENOMEM) { SOCKET_DEBUG(( "Not enough memory\n" )); }
+      m_error = wxSOCKET_TIMEDOUT;
+      return wxSOCKET_TIMEDOUT;
     }
 
     if ( ! wxFD_ISSET(m_fd, &writefds) )
     {
-        GSocket_Debug(( "GSocket_Output_Timeout is buggy!\n" ));
+        SOCKET_DEBUG(( "Output_Timeout is buggy!\n" ));
     }
     else
     {
-        GSocket_Debug(( "GSocket_Output_Timeout seems correct\n" ));
+        SOCKET_DEBUG(( "Output_Timeout seems correct\n" ));
     }
   }
   else
   {
-    GSocket_Debug(( "GSocket_Output_Timeout, didn't try select!\n" ));
+    SOCKET_DEBUG(( "Output_Timeout, didn't try select!\n" ));
   }
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-int GSocket::Recv_Stream(char *buffer, int size)
+int wxSocketImplUnix::Recv_Stream(char *buffer, int size)
 {
   int ret;
   do
@@ -1244,12 +884,12 @@ int GSocket::Recv_Stream(char *buffer, int size)
   return ret;
 }
 
-int GSocket::Recv_Dgram(char *buffer, int size)
+int wxSocketImplUnix::Recv_Dgram(char *buffer, int size)
 {
   wxSockAddr from;
   WX_SOCKLEN_T fromlen = sizeof(from);
   int ret;
-  GSocketError err;
+  wxSocketError err;
 
   fromlen = sizeof(from);
 
@@ -1262,19 +902,19 @@ int GSocket::Recv_Dgram(char *buffer, int size)
   if (ret == -1)
     return -1;
 
-  /* Translate a system address into a GSocket address */
+  /* Translate a system address into a wxSocketImplUnix address */
   if (!m_peer)
   {
     m_peer = GAddress_new();
     if (!m_peer)
     {
-      m_error = GSOCK_MEMERR;
+      m_error = wxSOCKET_MEMERR;
       return -1;
     }
   }
 
   err = _GAddress_translate_from(m_peer, (sockaddr*)&from, fromlen);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     GAddress_destroy(m_peer);
     m_peer  = NULL;
@@ -1285,7 +925,7 @@ int GSocket::Recv_Dgram(char *buffer, int size)
   return ret;
 }
 
-int GSocket::Send_Stream(const char *buffer, int size)
+int wxSocketImplUnix::Send_Stream(const char *buffer, int size)
 {
   int ret;
 
@@ -1302,20 +942,20 @@ int GSocket::Send_Stream(const char *buffer, int size)
   return ret;
 }
 
-int GSocket::Send_Dgram(const char *buffer, int size)
+int wxSocketImplUnix::Send_Dgram(const char *buffer, int size)
 {
   struct sockaddr *addr;
   int len, ret;
-  GSocketError err;
+  wxSocketError err;
 
   if (!m_peer)
   {
-    m_error = GSOCK_INVADDR;
+    m_error = wxSOCKET_INVADDR;
     return -1;
   }
 
   err = _GAddress_translate_to(m_peer, &addr, &len);
-  if (err != GSOCK_NOERROR)
+  if (err != wxSOCKET_NOERROR)
   {
     m_error = err;
     return -1;
@@ -1337,16 +977,16 @@ int GSocket::Send_Dgram(const char *buffer, int size)
   return ret;
 }
 
-void GSocket::OnStateChange(GSocketEvent event)
+void wxSocketImplUnix::OnStateChange(wxSocketNotify event)
 {
     DisableEvent(event);
     NotifyOnStateChange(event);
 
-    if ( event == GSOCK_LOST )
+    if ( event == wxSOCKET_LOST )
         Shutdown();
 }
 
-void GSocket::Detected_Read()
+void wxSocketImplUnix::Detected_Read()
 {
   char c;
 
@@ -1359,11 +999,11 @@ void GSocket::Detected_Read()
   /* If we have already detected a LOST event, then don't try
    * to do any further processing.
    */
-  if ((m_detected & GSOCK_LOST_FLAG) != 0)
+  if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
   {
     m_establishing = false;
 
-    OnStateChange(GSOCK_LOST);
+    OnStateChange(wxSOCKET_LOST);
     return;
   }
 
@@ -1371,25 +1011,25 @@ void GSocket::Detected_Read()
 
   if (num > 0)
   {
-    OnStateChange(GSOCK_INPUT);
+    OnStateChange(wxSOCKET_INPUT);
   }
   else
   {
     if (m_server && m_stream)
     {
-      OnStateChange(GSOCK_CONNECTION);
+      OnStateChange(wxSOCKET_CONNECTION);
     }
     else if (num == 0)
     {
       if (m_stream)
       {
         /* graceful shutdown */
-        OnStateChange(GSOCK_LOST);
+        OnStateChange(wxSOCKET_LOST);
       }
       else
       {
         /* Empty datagram received */
-        OnStateChange(GSOCK_INPUT);
+        OnStateChange(wxSOCKET_INPUT);
       }
     }
     else
@@ -1397,26 +1037,26 @@ void GSocket::Detected_Read()
       /* Do not throw a lost event in cases where the socket isn't really lost */
       if ((errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == EINTR))
       {
-        OnStateChange(GSOCK_INPUT);
+        OnStateChange(wxSOCKET_INPUT);
       }
       else
       {
-        OnStateChange(GSOCK_LOST);
+        OnStateChange(wxSOCKET_LOST);
       }
     }
   }
 }
 
-void GSocket::Detected_Write()
+void wxSocketImplUnix::Detected_Write()
 {
   /* If we have already detected a LOST event, then don't try
    * to do any further processing.
    */
-  if ((m_detected & GSOCK_LOST_FLAG) != 0)
+  if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
   {
     m_establishing = false;
 
-    OnStateChange(GSOCK_LOST);
+    OnStateChange(wxSOCKET_LOST);
     return;
   }
 
@@ -1431,21 +1071,21 @@ void GSocket::Detected_Write()
 
     if (error)
     {
-      OnStateChange(GSOCK_LOST);
+      OnStateChange(wxSOCKET_LOST);
     }
     else
     {
-      OnStateChange(GSOCK_CONNECTION);
+      OnStateChange(wxSOCKET_CONNECTION);
       /* We have to fire this event by hand because CONNECTION (for clients)
        * and OUTPUT are internally the same and we just disabled CONNECTION
        * events with the above macro.
        */
-      OnStateChange(GSOCK_OUTPUT);
+      OnStateChange(wxSOCKET_OUTPUT);
     }
   }
   else
   {
-    OnStateChange(GSOCK_OUTPUT);
+    OnStateChange(wxSOCKET_OUTPUT);
   }
 }
 
@@ -1456,32 +1096,32 @@ void GSocket::Detected_Write()
  */
 
 /* CHECK_ADDRESS verifies that the current address family is either
- * GSOCK_NOFAMILY or GSOCK_*family*, and if it is GSOCK_NOFAMILY, it
- * initalizes it to be a GSOCK_*family*. In other cases, it returns
+ * wxSOCKET_NOFAMILY or wxSOCKET_*family*, and if it is wxSOCKET_NOFAMILY, it
+ * initalizes it to be a wxSOCKET_*family*. In other cases, it returns
  * an appropiate error code.
  *
  * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error.
  */
 #define CHECK_ADDRESS(address, family)                              \
 {                                                                   \
-  if (address->m_family == GSOCK_NOFAMILY)                          \
-    if (_GAddress_Init_##family(address) != GSOCK_NOERROR)          \
+  if (address->m_family == wxSOCKET_NOFAMILY)                          \
+    if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \
       return address->m_error;                                      \
-  if (address->m_family != GSOCK_##family)                          \
+  if (address->m_family != wxSOCKET_##family)                          \
   {                                                                 \
-    address->m_error = GSOCK_INVADDR;                               \
-    return GSOCK_INVADDR;                                           \
+    address->m_error = wxSOCKET_INVADDR;                               \
+    return wxSOCKET_INVADDR;                                           \
   }                                                                 \
 }
 
 #define CHECK_ADDRESS_RETVAL(address, family, retval)               \
 {                                                                   \
-  if (address->m_family == GSOCK_NOFAMILY)                          \
-    if (_GAddress_Init_##family(address) != GSOCK_NOERROR)          \
+  if (address->m_family == wxSOCKET_NOFAMILY)                          \
+    if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \
       return retval;                                                \
-  if (address->m_family != GSOCK_##family)                          \
+  if (address->m_family != wxSOCKET_##family)                          \
   {                                                                 \
-    address->m_error = GSOCK_INVADDR;                               \
+    address->m_error = wxSOCKET_INVADDR;                               \
     return retval;                                                  \
   }                                                                 \
 }
@@ -1494,7 +1134,7 @@ GAddress *GAddress_new(void)
   if ((address = (GAddress *) malloc(sizeof(GAddress))) == NULL)
     return NULL;
 
-  address->m_family  = GSOCK_NOFAMILY;
+  address->m_family  = wxSOCKET_NOFAMILY;
   address->m_addr    = NULL;
   address->m_len     = 0;
 
@@ -1550,27 +1190,27 @@ GAddressType GAddress_GetFamily(GAddress *address)
   return address->m_family;
 }
 
-GSocketError _GAddress_translate_from(GAddress *address,
+wxSocketError _GAddress_translate_from(GAddress *address,
                                       struct sockaddr *addr, int len)
 {
   address->m_realfamily = addr->sa_family;
   switch (addr->sa_family)
   {
     case AF_INET:
-      address->m_family = GSOCK_INET;
+      address->m_family = wxSOCKET_INET;
       break;
     case AF_UNIX:
-      address->m_family = GSOCK_UNIX;
+      address->m_family = wxSOCKET_UNIX;
       break;
 #if wxUSE_IPV6
     case AF_INET6:
-      address->m_family = GSOCK_INET6;
+      address->m_family = wxSOCKET_INET6;
       break;
 #endif // wxUSE_IPV6
     default:
     {
-      address->m_error = GSOCK_INVOP;
-      return GSOCK_INVOP;
+      address->m_error = wxSOCKET_INVOP;
+      return wxSOCKET_INVOP;
     }
   }
 
@@ -1582,34 +1222,34 @@ GSocketError _GAddress_translate_from(GAddress *address,
 
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
   memcpy(address->m_addr, addr, len);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError _GAddress_translate_to(GAddress *address,
+wxSocketError _GAddress_translate_to(GAddress *address,
                                     struct sockaddr **addr, int *len)
 {
   if (!address->m_addr)
   {
-    address->m_error = GSOCK_INVADDR;
-    return GSOCK_INVADDR;
+    address->m_error = wxSOCKET_INVADDR;
+    return wxSOCKET_INVADDR;
   }
 
   *len = address->m_len;
   *addr = (struct sockaddr *)malloc(address->m_len);
   if (*addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
   memcpy(*addr, address->m_addr, address->m_len);
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 /*
@@ -1618,25 +1258,25 @@ GSocketError _GAddress_translate_to(GAddress *address,
  * -------------------------------------------------------------------------
  */
 
-GSocketError _GAddress_Init_INET(GAddress *address)
+wxSocketError _GAddress_Init_INET(GAddress *address)
 {
   address->m_len  = sizeof(struct sockaddr_in);
   address->m_addr = (struct sockaddr *) malloc(address->m_len);
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
-  address->m_family = GSOCK_INET;
+  address->m_family = wxSOCKET_INET;
   address->m_realfamily = PF_INET;
   ((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET;
   ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_ANY;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
+wxSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
 {
   struct hostent *he;
   struct in_addr *addr;
@@ -1677,29 +1317,29 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
     {
       /* Reset to invalid address */
       addr->s_addr = INADDR_NONE;
-      address->m_error = GSOCK_NOHOST;
-      return GSOCK_NOHOST;
+      address->m_error = wxSOCKET_NOHOST;
+      return wxSOCKET_NOHOST;
     }
 
     array_addr = (struct in_addr *) *(he->h_addr_list);
     addr->s_addr = array_addr[0].s_addr;
   }
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 
-GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
+wxSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
 {
   return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
 }
 
-GSocketError GAddress_INET_SetAnyAddress(GAddress *address)
+wxSocketError GAddress_INET_SetAnyAddress(GAddress *address)
 {
   return GAddress_INET_SetHostAddress(address, INADDR_ANY);
 }
 
-GSocketError GAddress_INET_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET_SetHostAddress(GAddress *address,
                                           unsigned long hostaddr)
 {
   struct in_addr *addr;
@@ -1711,10 +1351,10 @@ GSocketError GAddress_INET_SetHostAddress(GAddress *address,
   addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
   addr->s_addr = htonl(hostaddr);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
                                        const char *protocol)
 {
   struct servent *se;
@@ -1725,8 +1365,8 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
 
   if (!port)
   {
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
 #if defined(HAVE_FUNC_GETSERVBYNAME_R_4)
@@ -1748,20 +1388,20 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
       port_int = atoi(port);
       addr = (struct sockaddr_in *)address->m_addr;
       addr->sin_port = htons(port_int);
-      return GSOCK_NOERROR;
+      return wxSOCKET_NOERROR;
     }
 
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   addr = (struct sockaddr_in *)address->m_addr;
   addr->sin_port = se->s_port;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
+wxSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
 {
   struct sockaddr_in *addr;
 
@@ -1771,10 +1411,10 @@ GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
   addr = (struct sockaddr_in *)address->m_addr;
   addr->sin_port = htons(port);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
+wxSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
 {
   struct hostent *he;
   char *addr_buf;
@@ -1797,13 +1437,13 @@ GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t
                         (void*)&buffer, sizeof(buffer), &err);
   if (he == NULL)
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   strncpy(hostname, he->h_name, sbuf);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 unsigned long GAddress_INET_GetHostAddress(GAddress *address)
@@ -1836,27 +1476,27 @@ unsigned short GAddress_INET_GetPort(GAddress *address)
  * -------------------------------------------------------------------------
  */
 
-GSocketError _GAddress_Init_INET6(GAddress *address)
+wxSocketError _GAddress_Init_INET6(GAddress *address)
 {
   struct in6_addr any_address = IN6ADDR_ANY_INIT;
   address->m_len  = sizeof(struct sockaddr_in6);
   address->m_addr = (struct sockaddr *) malloc(address->m_len);
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
   memset(address->m_addr,0,address->m_len);
 
-  address->m_family = GSOCK_INET6;
+  address->m_family = wxSOCKET_INET6;
   address->m_realfamily = AF_INET6;
   ((struct sockaddr_in6 *)address->m_addr)->sin6_family = AF_INET6;
   ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = any_address;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
+wxSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
 {
   assert(address != NULL);
   CHECK_ADDRESS(address, INET6);
@@ -1867,16 +1507,16 @@ GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
   addrinfo * info = 0;
   if ( getaddrinfo( hostname, "0", & hints, & info ) || ! info )
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   memcpy( address->m_addr, info->ai_addr, info->ai_addrlen );
   freeaddrinfo( info );
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
+wxSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
 {
   assert(address != NULL);
 
@@ -1886,7 +1526,7 @@ GSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
   memset( & addr, 0, sizeof( addr ) );
   return GAddress_INET6_SetHostAddress(address, addr);
 }
-GSocketError GAddress_INET6_SetHostAddress(GAddress *address,
+wxSocketError GAddress_INET6_SetHostAddress(GAddress *address,
                                           struct in6_addr hostaddr)
 {
   assert(address != NULL);
@@ -1895,10 +1535,10 @@ GSocketError GAddress_INET6_SetHostAddress(GAddress *address,
 
   ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = hostaddr;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
+wxSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
                                        const char *protocol)
 {
   struct servent *se;
@@ -1909,8 +1549,8 @@ GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
 
   if (!port)
   {
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   se = getservbyname(port, protocol);
@@ -1923,20 +1563,20 @@ GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
       port_int = atoi(port);
       addr = (struct sockaddr_in6 *)address->m_addr;
       addr->sin6_port = htons((u_short) port_int);
-      return GSOCK_NOERROR;
+      return wxSOCKET_NOERROR;
     }
 
-    address->m_error = GSOCK_INVPORT;
-    return GSOCK_INVPORT;
+    address->m_error = wxSOCKET_INVPORT;
+    return wxSOCKET_INVPORT;
   }
 
   addr = (struct sockaddr_in6 *)address->m_addr;
   addr->sin6_port = se->s_port;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
+wxSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
 {
   struct sockaddr_in6 *addr;
 
@@ -1946,10 +1586,10 @@ GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
   addr = (struct sockaddr_in6 *)address->m_addr;
   addr->sin6_port = htons(port);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
+wxSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
 {
   struct hostent *he;
   char *addr_buf;
@@ -1964,22 +1604,22 @@ GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_
   he = gethostbyaddr(addr_buf, sizeof(addr->sin6_addr), AF_INET6);
   if (he == NULL)
   {
-    address->m_error = GSOCK_NOHOST;
-    return GSOCK_NOHOST;
+    address->m_error = wxSOCKET_NOHOST;
+    return wxSOCKET_NOHOST;
   }
 
   strncpy(hostname, he->h_name, sbuf);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
+wxSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
 {
   assert(address != NULL);
   assert(hostaddr != NULL);
-  CHECK_ADDRESS_RETVAL(address, INET6, GSOCK_INVADDR);
+  CHECK_ADDRESS_RETVAL(address, INET6, wxSOCKET_INVADDR);
   *hostaddr = ( (struct sockaddr_in6 *)address->m_addr )->sin6_addr;
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 unsigned short GAddress_INET6_GetPort(GAddress *address)
@@ -1999,27 +1639,27 @@ unsigned short GAddress_INET6_GetPort(GAddress *address)
  */
 
 #ifndef __VISAGECPP__
-GSocketError _GAddress_Init_UNIX(GAddress *address)
+wxSocketError _GAddress_Init_UNIX(GAddress *address)
 {
   address->m_len  = sizeof(struct sockaddr_un);
   address->m_addr = (struct sockaddr *)malloc(address->m_len);
   if (address->m_addr == NULL)
   {
-    address->m_error = GSOCK_MEMERR;
-    return GSOCK_MEMERR;
+    address->m_error = wxSOCKET_MEMERR;
+    return wxSOCKET_MEMERR;
   }
 
-  address->m_family = GSOCK_UNIX;
+  address->m_family = wxSOCKET_UNIX;
   address->m_realfamily = PF_UNIX;
   ((struct sockaddr_un *)address->m_addr)->sun_family = AF_UNIX;
   ((struct sockaddr_un *)address->m_addr)->sun_path[0] = 0;
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
 #define UNIX_SOCK_PATHLEN (sizeof(addr->sun_path)/sizeof(addr->sun_path[0]))
 
-GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path)
+wxSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path)
 {
   struct sockaddr_un *addr;
 
@@ -2031,10 +1671,10 @@ GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path)
   strncpy(addr->sun_path, path, UNIX_SOCK_PATHLEN);
   addr->sun_path[UNIX_SOCK_PATHLEN - 1] = '\0';
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 
-GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf)
+wxSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf)
 {
   struct sockaddr_un *addr;
 
@@ -2045,7 +1685,7 @@ GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf)
 
   strncpy(path, addr->sun_path, sbuf);
 
-  return GSOCK_NOERROR;
+  return wxSOCKET_NOERROR;
 }
 #endif  /* !defined(__VISAGECPP__) */
 #endif  /* wxUSE_SOCKETS */