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@
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 \
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
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
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
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
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 \
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 \
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
-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
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 \
@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 = \
@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 \
@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 = \
-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
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 \
@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 \
-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
@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 = \
@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 = \
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
-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
@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
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
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
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
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
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
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
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
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
<!-- 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
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
<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">
$(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>
class WXDLLIMPEXP_FWD_BASE wxTimer;
class WXDLLIMPEXP_FWD_BASE wxTimerImpl;
-class GSocketManager;
+class wxSocketManager;
// ----------------------------------------------------------------------------
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
// utility function: returns the stack frame as a plain wxString
virtual wxString GetAssertStackTrace();
#endif
+
+private:
+ static wxSocketManager *ms_manager;
};
// ----------------------------------------------------------------------------
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
// ---------------
// 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_
-/* -------------------------------------------------------------------------
- * 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_ */
// 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
};
virtual wxString GetDesktopEnvironment() const;
#endif
#if wxUSE_SOCKETS
- virtual GSocketManager *GetSocketManager();
+ virtual wxSocketManager *GetSocketManager();
#endif
};
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/gsocket.h
-// Purpose: GSocket implementation
+// Purpose: wxSocketImpl nd related declarations
// Authors: Guilhem Lavaux, Vadim Zeitlin
// Created: April 1997
// RCS-ID: $Id$
// 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_
#if wxUSE_SOCKETS
-#include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
-
-class WXDLLIMPEXP_FWD_NET wxSocketBase;
+#include "wx/socket.h"
#include <stddef.h>
#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
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();
// 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
// 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;
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
GAddressType m_family;
int m_realfamily;
- GSocketError m_error;
+ wxSocketError m_error;
};
GAddress *GAddress_new();
* 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 */
/////////////////////////////////////////////////////////////////////////////
// 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;
virtual void OnExceptionWaiting() { m_socket->Detected_Read(); }
private:
- GSocket* m_socket;
+ wxSocketImpl *m_socket;
int m_flags;
};
#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;
-
// --------------------------------------------------------------------------
// 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();
// 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
// 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
private:
// socket
- GSocket *m_socket; // GSocket
+ wxSocketImpl *m_impl; // port-specific implementation
wxSocketType m_type; // wxSocket type
// state
// the signal handlers
WX_DECLARE_HASH_MAP(int, SignalHandler, wxIntegerHash, wxIntegerEqual, SignalHandlerHash);
SignalHandlerHash m_signalHandlerHash;
-
- friend class GSocketGUIFunctionsTableBase;
};
// 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:
#endif
#if wxUSE_SOCKETS && defined(wxHAS_GUI_SOCKET_MANAGER)
- virtual GSocketManager *GetSocketManager();
+ virtual wxSocketManager *GetSocketManager();
#endif
};
-/* -------------------------------------------------------------------------
- * 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);
//
// 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
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:
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 )
{
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" );
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);
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;
};
wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL;
+wxSocketManager *wxAppTraitsBase::ms_manager = NULL;
+
// ----------------------------------------------------------------------------
// wxEventLoopPtr
// ----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// 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 )
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;
else // no existing handler
{
registerHandler = true;
- handler = new wxGSocketIOHandler(socket);
+ handler = new wxSocketIOHandler(socket);
}
FD(socket, d) = fd;
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);
if ( !dispatcher )
return;
- wxGSocketIOHandler *& handler = socket->m_handler;
+ wxSocketIOHandler *& handler = socket->m_handler;
if ( handler )
{
handler->RemoveFlag(flag);
}
}
-GSocketManager *wxAppTraits::GetSocketManager()
+wxSocketManager *wxAppTraits::GetSocketManager()
{
- static GSocketSelectManager s_manager;
+ static wxSocketSelectManager s_manager;
return &s_manager;
}
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
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
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
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])
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
bool wxIPV6address::AnyAddress()
{
- return (GAddress_INET6_SetAnyAddress(m_address) == GSOCK_NOERROR);
+ return (GAddress_INET6_SetAnyAddress(m_address) == wxSOCKET_NOERROR);
}
wxString wxIPV6address::IPAddress() const
if ( GAddress_INET6_GetHostName(m_address,
hostname,
- WXSIZEOF(hostname)) != GSOCK_NOERROR )
+ WXSIZEOF(hostname)) != wxSOCKET_NOERROR )
return wxEmptyString;
return wxString::FromAscii(hostname);
// 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
/////////////////////////////////////////////////////////////////////////////
#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"
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" );
}
/* static */
-void GSocketManager::Init()
+void wxSocketManager::Init()
{
wxASSERT_MSG( !ms_manager, "shouldn't be initialized twice" );
}
// ==========================================================================
-// 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;
m_initialSendBufferSize = -1;
}
-GSocketBase::~GSocketBase()
+wxSocketImpl::~wxSocketImpl()
{
if (m_fd != INVALID_SOCKET)
Shutdown();
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 )
{
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)
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)
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)
/* 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;
return address;
}
-GAddress *GSocketBase::GetPeer()
+GAddress *wxSocketImpl::GetPeer()
{
/* try to get it from the m_peer var */
if (m_peer)
{
if ( !m_countInit++ )
{
- if ( !GSocket_Init() )
+ wxSocketManager * const manager = wxSocketManager::Get();
+ if ( !manager || !manager->OnInit() )
{
m_countInit--;
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();
}
}
void wxSocketBase::Init()
{
- m_socket = NULL;
+ m_impl = NULL;
m_type = wxSOCKET_UNINIT;
// state
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)
return true;
}
+// ----------------------------------------------------------------------------
+// simply accessors
+// ----------------------------------------------------------------------------
+
+wxSocketError wxSocketBase::LastError() const
+{
+ return m_impl->GetError();
+}
+
// --------------------------------------------------------------------------
// Basic IO calls
// --------------------------------------------------------------------------
// Interrupt pending waits
InterruptWait();
- if (m_socket)
- m_socket->Shutdown();
+ if (m_impl)
+ m_impl->Shutdown();
m_connected = false;
m_establishing = false;
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" );
// 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;
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
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" );
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;
}
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;
// 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;
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 */
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;
}
}
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
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;
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;
}
// 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;
}
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
);
}
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);
}
// --------------------------------------------------------------------------
{
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
{
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);
{
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)
// 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;
m_connected = false;
m_establishing = false;
break;
+
+ case wxSOCKET_MAX_EVENT:
+ wxFAIL_MSG( "unexpected notification" );
+ return;
}
// Schedule the event
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;
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)
{
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 );
}
// --------------------------------------------------------------------------
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;
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)
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
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;
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;
}
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);
}
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;
}
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
);
}
}
};
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
{
static GTKSocketManager s_manager;
return &s_manager;
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
);
}
}
};
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
{
static GTKSocketManager s_manager;
return &s_manager;
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
(
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
);
}
}
};
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
{
static MotifSocketManager s_manager;
return &s_manager;
// wxAppTraits implementation
// ============================================================================
-GSocketManager *wxAppTraits::ms_manager = NULL;
-
WXDWORD wxAppTraits::DoSimpleWaitForThread(WXHANDLE hThread)
{
return ::WaitForSingleObject((HANDLE)hThread, INFINITE);
/* -------------------------------------------------------------------------
- * 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$
* -------------------------------------------------------------------------
#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;
}
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;
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;
}
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;
}
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 */
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;
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;
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;
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;
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;
*/
/* 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; \
} \
}
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;
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;
}
}
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;
}
/*
* -------------------------------------------------------------------------
*/
-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;
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;
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;
if (!port)
{
- address->m_error = GSOCK_INVPORT;
- return GSOCK_INVPORT;
+ address->m_error = wxSOCKET_INVPORT;
+ return wxSOCKET_INVPORT;
}
se = getservbyname(port, protocol);
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;
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;
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)
#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);
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);
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;
if (!port)
{
- address->m_error = GSOCK_INVPORT;
- return GSOCK_INVPORT;
+ address->m_error = wxSOCKET_INVPORT;
+ return wxSOCKET_INVPORT;
}
se = getservbyname(port, protocol);
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;
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;
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)
* -------------------------------------------------------------------------
*/
-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
-/* -------------------------------------------------------------------------
- * 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"
# 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)
*/
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__
#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;
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 */
/* 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;
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
/* 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
{
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);
}
* 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
/*
* 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__
}
}
-// 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;
/* -------------------------------------------------------------------------
- * 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)
}
};
-GSocketManager *wxGUIAppTraits::GetSocketManager()
+wxSocketManager *wxGUIAppTraits::GetSocketManager()
{
static PMSocketManager s_manager;
return &s_manager;
-/* -------------------------------------------------------------------------
- * 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>
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
m_socket = CFSocketCreateWithNative
(
NULL, // default allocator
- socket->m_fd,
+ m_fd,
kCFSocketReadCallBack |
kCFSocketWriteCallBack |
kCFSocketConnectCallBack,
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)
{
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)
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
-/* -------------------------------------------------------------------------
- * 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"
/* 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;
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;
return connection;
}
-void GSocket::Notify(bool flag)
+void wxSocketImplUnix::Notify(bool flag)
{
if (flag == m_use_events)
return;
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
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
{
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;
/* 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;
}
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)
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
* 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;
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;
// 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)
{
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
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);
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;
return ret;
}
-int GSocket::Send_Stream(const char *buffer, int size)
+int wxSocketImplUnix::Send_Stream(const char *buffer, int size)
{
int ret;
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;
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;
/* 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;
}
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
/* 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;
}
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);
}
}
*/
/* 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; \
} \
}
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;
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;
}
}
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;
}
/*
* -------------------------------------------------------------------------
*/
-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;
{
/* 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;
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;
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)
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;
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;
(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)
* -------------------------------------------------------------------------
*/
-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);
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);
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);
((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;
if (!port)
{
- address->m_error = GSOCK_INVPORT;
- return GSOCK_INVPORT;
+ address->m_error = wxSOCKET_INVPORT;
+ return wxSOCKET_INVPORT;
}
se = getservbyname(port, protocol);
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;
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;
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)
*/
#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;
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;
strncpy(path, addr->sun_path, sbuf);
- return GSOCK_NOERROR;
+ return wxSOCKET_NOERROR;
}
#endif /* !defined(__VISAGECPP__) */
#endif /* wxUSE_SOCKETS */