merge msw/gsocket.cpp into msw/sockmsw.cpp
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57552 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
49
Makefile.in
49
Makefile.in
@@ -806,7 +806,6 @@ ALL_BASE_SOURCES = \
|
||||
src/common/socketiohandler.cpp \
|
||||
src/unix/sockunix.cpp \
|
||||
src/osx/core/sockosx.cpp \
|
||||
src/msw/gsocket.cpp \
|
||||
src/msw/sockmsw.cpp \
|
||||
src/msw/urlmsw.cpp \
|
||||
$(NET_WINCE_SRC) \
|
||||
@@ -4044,12 +4043,9 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS = \
|
||||
@COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS = monodll_sockunix.o
|
||||
@COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS = \
|
||||
@COND_PLATFORM_UNIX_1@ monodll_socketiohandler.o monodll_sockunix.o
|
||||
COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS = \
|
||||
monodll_gsocket.o \
|
||||
monodll_sockmsw.o \
|
||||
monodll_urlmsw.o \
|
||||
$(__NET_WINCE_SRC_OBJECTS)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS = $(COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS = \
|
||||
@COND_PLATFORM_WIN32_1@ monodll_sockmsw.o monodll_urlmsw.o \
|
||||
@COND_PLATFORM_WIN32_1@ $(__NET_WINCE_SRC_OBJECTS)
|
||||
@COND_TOOLKIT_WINCE@__NET_WINCE_SRC_OBJECTS = monodll_net.o
|
||||
COND_USE_GUI_1___MONOLIB_GUI_SRC_OBJECTS = \
|
||||
$(__CORE_SRC_OBJECTS) \
|
||||
@@ -5866,12 +5862,9 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_1 = \
|
||||
@COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_1 = monolib_sockunix.o
|
||||
@COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_1 = \
|
||||
@COND_PLATFORM_UNIX_1@ monolib_socketiohandler.o monolib_sockunix.o
|
||||
COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_1 = \
|
||||
monolib_gsocket.o \
|
||||
monolib_sockmsw.o \
|
||||
monolib_urlmsw.o \
|
||||
$(__NET_WINCE_SRC_OBJECTS_1)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_1 = $(COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_1)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_1 \
|
||||
@COND_PLATFORM_WIN32_1@ = monolib_sockmsw.o monolib_urlmsw.o \
|
||||
@COND_PLATFORM_WIN32_1@ $(__NET_WINCE_SRC_OBJECTS_1)
|
||||
@COND_TOOLKIT_WINCE@__NET_WINCE_SRC_OBJECTS_1 = monolib_net.o
|
||||
COND_USE_GUI_1___MONOLIB_GUI_SRC_OBJECTS_1 = \
|
||||
$(__CORE_SRC_OBJECTS_1) \
|
||||
@@ -7869,12 +7862,9 @@ COND_USE_SOSYMLINKS_1___netdll___so_symlinks_uninst_cmd = rm -f \
|
||||
@COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_2 = netdll_sockunix.o
|
||||
@COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_2 = \
|
||||
@COND_PLATFORM_UNIX_1@ netdll_socketiohandler.o netdll_sockunix.o
|
||||
COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_2 = \
|
||||
netdll_gsocket.o \
|
||||
netdll_sockmsw.o \
|
||||
netdll_urlmsw.o \
|
||||
$(__NET_WINCE_SRC_OBJECTS_2)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_2 = $(COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_2)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_2 \
|
||||
@COND_PLATFORM_WIN32_1@ = netdll_sockmsw.o netdll_urlmsw.o \
|
||||
@COND_PLATFORM_WIN32_1@ $(__NET_WINCE_SRC_OBJECTS_2)
|
||||
@COND_TOOLKIT_WINCE@__NET_WINCE_SRC_OBJECTS_2 = netdll_net.o
|
||||
COND_MONOLITHIC_0_SHARED_0___netlib___depname = \
|
||||
$(LIBDIRNAME)/$(LIBPREFIX)wx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_net-$(WX_RELEASE)$(HOST_SUFFIX)$(LIBEXT)
|
||||
@@ -7892,12 +7882,9 @@ COND_MONOLITHIC_0_SHARED_0___netlib___depname = \
|
||||
@COND_PLATFORM_OS2_1@__NET_PLATFORM_SRC_OBJECTS_3 = netlib_sockunix.o
|
||||
@COND_PLATFORM_UNIX_1@__NET_PLATFORM_SRC_OBJECTS_3 = \
|
||||
@COND_PLATFORM_UNIX_1@ netlib_socketiohandler.o netlib_sockunix.o
|
||||
COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_3 = \
|
||||
netlib_gsocket.o \
|
||||
netlib_sockmsw.o \
|
||||
netlib_urlmsw.o \
|
||||
$(__NET_WINCE_SRC_OBJECTS_3)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_3 = $(COND_PLATFORM_WIN32_1___NET_PLATFORM_SRC_OBJECTS_3)
|
||||
@COND_PLATFORM_WIN32_1@__NET_PLATFORM_SRC_OBJECTS_3 \
|
||||
@COND_PLATFORM_WIN32_1@ = netlib_sockmsw.o netlib_urlmsw.o \
|
||||
@COND_PLATFORM_WIN32_1@ $(__NET_WINCE_SRC_OBJECTS_3)
|
||||
@COND_TOOLKIT_WINCE@__NET_WINCE_SRC_OBJECTS_3 = netlib_net.o
|
||||
@COND_SHARED_1@____wxnet_namedll_DEP = $(__netdll___depname)
|
||||
@COND_SHARED_0@____wxnet_namelib_DEP = $(__netlib___depname)
|
||||
@@ -14549,9 +14536,6 @@ monodll_socket.o: $(srcdir)/src/common/socket.cpp $(MONODLL_ODEP)
|
||||
monodll_url.o: $(srcdir)/src/common/url.cpp $(MONODLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/url.cpp
|
||||
|
||||
monodll_gsocket.o: $(srcdir)/src/msw/gsocket.cpp $(MONODLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/gsocket.cpp
|
||||
|
||||
monodll_sockmsw.o: $(srcdir)/src/msw/sockmsw.cpp $(MONODLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/sockmsw.cpp
|
||||
|
||||
@@ -19247,9 +19231,6 @@ monolib_socket.o: $(srcdir)/src/common/socket.cpp $(MONOLIB_ODEP)
|
||||
monolib_url.o: $(srcdir)/src/common/url.cpp $(MONOLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/url.cpp
|
||||
|
||||
monolib_gsocket.o: $(srcdir)/src/msw/gsocket.cpp $(MONOLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/gsocket.cpp
|
||||
|
||||
monolib_sockmsw.o: $(srcdir)/src/msw/sockmsw.cpp $(MONOLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/sockmsw.cpp
|
||||
|
||||
@@ -24497,9 +24478,6 @@ netdll_socket.o: $(srcdir)/src/common/socket.cpp $(NETDLL_ODEP)
|
||||
netdll_url.o: $(srcdir)/src/common/url.cpp $(NETDLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/common/url.cpp
|
||||
|
||||
netdll_gsocket.o: $(srcdir)/src/msw/gsocket.cpp $(NETDLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/msw/gsocket.cpp
|
||||
|
||||
netdll_sockmsw.o: $(srcdir)/src/msw/sockmsw.cpp $(NETDLL_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETDLL_CXXFLAGS) $(srcdir)/src/msw/sockmsw.cpp
|
||||
|
||||
@@ -24557,9 +24535,6 @@ netlib_socket.o: $(srcdir)/src/common/socket.cpp $(NETLIB_ODEP)
|
||||
netlib_url.o: $(srcdir)/src/common/url.cpp $(NETLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/common/url.cpp
|
||||
|
||||
netlib_gsocket.o: $(srcdir)/src/msw/gsocket.cpp $(NETLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/msw/gsocket.cpp
|
||||
|
||||
netlib_sockmsw.o: $(srcdir)/src/msw/sockmsw.cpp $(NETLIB_ODEP)
|
||||
$(CXXC) -c -o $@ $(NETLIB_CXXFLAGS) $(srcdir)/src/msw/sockmsw.cpp
|
||||
|
||||
|
@@ -542,7 +542,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
||||
</set>
|
||||
|
||||
<set var="NET_WIN32_SRC" hints="files">
|
||||
src/msw/gsocket.cpp
|
||||
src/msw/sockmsw.cpp
|
||||
src/msw/urlmsw.cpp
|
||||
</set>
|
||||
|
@@ -419,7 +419,6 @@ MONODLL_OBJECTS = \
|
||||
$(OBJS)\monodll_sckstrm.obj \
|
||||
$(OBJS)\monodll_socket.obj \
|
||||
$(OBJS)\monodll_url.obj \
|
||||
$(OBJS)\monodll_gsocket.obj \
|
||||
$(OBJS)\monodll_sockmsw.obj \
|
||||
$(OBJS)\monodll_urlmsw.obj \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_OBJECTS) \
|
||||
@@ -558,7 +557,6 @@ MONOLIB_OBJECTS = \
|
||||
$(OBJS)\monolib_sckstrm.obj \
|
||||
$(OBJS)\monolib_socket.obj \
|
||||
$(OBJS)\monolib_url.obj \
|
||||
$(OBJS)\monolib_gsocket.obj \
|
||||
$(OBJS)\monolib_sockmsw.obj \
|
||||
$(OBJS)\monolib_urlmsw.obj \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_1_OBJECTS) \
|
||||
@@ -824,7 +822,6 @@ NETDLL_OBJECTS = \
|
||||
$(OBJS)\netdll_sckstrm.obj \
|
||||
$(OBJS)\netdll_socket.obj \
|
||||
$(OBJS)\netdll_url.obj \
|
||||
$(OBJS)\netdll_gsocket.obj \
|
||||
$(OBJS)\netdll_sockmsw.obj \
|
||||
$(OBJS)\netdll_urlmsw.obj
|
||||
NETLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
|
||||
@@ -847,7 +844,6 @@ NETLIB_OBJECTS = \
|
||||
$(OBJS)\netlib_sckstrm.obj \
|
||||
$(OBJS)\netlib_socket.obj \
|
||||
$(OBJS)\netlib_url.obj \
|
||||
$(OBJS)\netlib_gsocket.obj \
|
||||
$(OBJS)\netlib_sockmsw.obj \
|
||||
$(OBJS)\netlib_urlmsw.obj
|
||||
COREDLL_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
|
||||
@@ -5717,9 +5713,6 @@ $(OBJS)\monodll_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monodll_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\monodll_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\monodll_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -7931,9 +7924,6 @@ $(OBJS)\monolib_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monolib_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\monolib_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\monolib_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -10460,9 +10450,6 @@ $(OBJS)\netdll_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netdll_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETDLL_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\netdll_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETDLL_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\netdll_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETDLL_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -10502,9 +10489,6 @@ $(OBJS)\netlib_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netlib_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETLIB_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\netlib_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETLIB_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\netlib_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -q -c -P -o$@ $(NETLIB_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
|
@@ -405,7 +405,6 @@ MONODLL_OBJECTS = \
|
||||
$(OBJS)\monodll_sckstrm.o \
|
||||
$(OBJS)\monodll_socket.o \
|
||||
$(OBJS)\monodll_url.o \
|
||||
$(OBJS)\monodll_gsocket.o \
|
||||
$(OBJS)\monodll_sockmsw.o \
|
||||
$(OBJS)\monodll_urlmsw.o \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_OBJECTS) \
|
||||
@@ -545,7 +544,6 @@ MONOLIB_OBJECTS = \
|
||||
$(OBJS)\monolib_sckstrm.o \
|
||||
$(OBJS)\monolib_socket.o \
|
||||
$(OBJS)\monolib_url.o \
|
||||
$(OBJS)\monolib_gsocket.o \
|
||||
$(OBJS)\monolib_sockmsw.o \
|
||||
$(OBJS)\monolib_urlmsw.o \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_1_OBJECTS) \
|
||||
@@ -815,7 +813,6 @@ NETDLL_OBJECTS = \
|
||||
$(OBJS)\netdll_sckstrm.o \
|
||||
$(OBJS)\netdll_socket.o \
|
||||
$(OBJS)\netdll_url.o \
|
||||
$(OBJS)\netdll_gsocket.o \
|
||||
$(OBJS)\netdll_sockmsw.o \
|
||||
$(OBJS)\netdll_urlmsw.o
|
||||
NETLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
|
||||
@@ -838,7 +835,6 @@ NETLIB_OBJECTS = \
|
||||
$(OBJS)\netlib_sckstrm.o \
|
||||
$(OBJS)\netlib_socket.o \
|
||||
$(OBJS)\netlib_url.o \
|
||||
$(OBJS)\netlib_gsocket.o \
|
||||
$(OBJS)\netlib_sockmsw.o \
|
||||
$(OBJS)\netlib_urlmsw.o
|
||||
COREDLL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) \
|
||||
@@ -5869,9 +5865,6 @@ $(OBJS)\monodll_socket.o: ../../src/common/socket.cpp
|
||||
$(OBJS)\monodll_url.o: ../../src/common/url.cpp
|
||||
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\monodll_gsocket.o: ../../src/msw/gsocket.cpp
|
||||
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\monodll_sockmsw.o: ../../src/msw/sockmsw.cpp
|
||||
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
@@ -8197,9 +8190,6 @@ $(OBJS)\monolib_socket.o: ../../src/common/socket.cpp
|
||||
$(OBJS)\monolib_url.o: ../../src/common/url.cpp
|
||||
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\monolib_gsocket.o: ../../src/msw/gsocket.cpp
|
||||
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\monolib_sockmsw.o: ../../src/msw/sockmsw.cpp
|
||||
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
@@ -10840,9 +10830,6 @@ $(OBJS)\netdll_socket.o: ../../src/common/socket.cpp
|
||||
$(OBJS)\netdll_url.o: ../../src/common/url.cpp
|
||||
$(CXX) -c -o $@ $(NETDLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\netdll_gsocket.o: ../../src/msw/gsocket.cpp
|
||||
$(CXX) -c -o $@ $(NETDLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\netdll_sockmsw.o: ../../src/msw/sockmsw.cpp
|
||||
$(CXX) -c -o $@ $(NETDLL_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
@@ -10882,9 +10869,6 @@ $(OBJS)\netlib_socket.o: ../../src/common/socket.cpp
|
||||
$(OBJS)\netlib_url.o: ../../src/common/url.cpp
|
||||
$(CXX) -c -o $@ $(NETLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\netlib_gsocket.o: ../../src/msw/gsocket.cpp
|
||||
$(CXX) -c -o $@ $(NETLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\netlib_sockmsw.o: ../../src/msw/sockmsw.cpp
|
||||
$(CXX) -c -o $@ $(NETLIB_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@@ -420,7 +420,6 @@ MONODLL_OBJECTS = \
|
||||
$(OBJS)\monodll_sckstrm.obj \
|
||||
$(OBJS)\monodll_socket.obj \
|
||||
$(OBJS)\monodll_url.obj \
|
||||
$(OBJS)\monodll_gsocket.obj \
|
||||
$(OBJS)\monodll_sockmsw.obj \
|
||||
$(OBJS)\monodll_urlmsw.obj \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_OBJECTS) \
|
||||
@@ -564,7 +563,6 @@ MONOLIB_OBJECTS = \
|
||||
$(OBJS)\monolib_sckstrm.obj \
|
||||
$(OBJS)\monolib_socket.obj \
|
||||
$(OBJS)\monolib_url.obj \
|
||||
$(OBJS)\monolib_gsocket.obj \
|
||||
$(OBJS)\monolib_sockmsw.obj \
|
||||
$(OBJS)\monolib_urlmsw.obj \
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_1_OBJECTS) \
|
||||
@@ -845,7 +843,6 @@ NETDLL_OBJECTS = \
|
||||
$(OBJS)\netdll_sckstrm.obj \
|
||||
$(OBJS)\netdll_socket.obj \
|
||||
$(OBJS)\netdll_url.obj \
|
||||
$(OBJS)\netdll_gsocket.obj \
|
||||
$(OBJS)\netdll_sockmsw.obj \
|
||||
$(OBJS)\netdll_urlmsw.obj
|
||||
NETLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_167)$(__DEBUGRUNTIME) /DWIN32 \
|
||||
@@ -871,7 +868,6 @@ NETLIB_OBJECTS = \
|
||||
$(OBJS)\netlib_sckstrm.obj \
|
||||
$(OBJS)\netlib_socket.obj \
|
||||
$(OBJS)\netlib_url.obj \
|
||||
$(OBJS)\netlib_gsocket.obj \
|
||||
$(OBJS)\netlib_sockmsw.obj \
|
||||
$(OBJS)\netlib_urlmsw.obj
|
||||
COREDLL_CXXFLAGS = /M$(__RUNTIME_LIBS_181)$(__DEBUGRUNTIME) /DWIN32 \
|
||||
@@ -6063,9 +6059,6 @@ $(OBJS)\monodll_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monodll_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\monodll_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\monodll_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -8277,9 +8270,6 @@ $(OBJS)\monolib_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monolib_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\monolib_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\monolib_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -10806,9 +10796,6 @@ $(OBJS)\netdll_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netdll_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETDLL_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\netdll_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETDLL_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\netdll_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETDLL_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
@@ -10848,9 +10835,6 @@ $(OBJS)\netlib_socket.obj: ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netlib_url.obj: ..\..\src\common\url.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETLIB_CXXFLAGS) ..\..\src\common\url.cpp
|
||||
|
||||
$(OBJS)\netlib_gsocket.obj: ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETLIB_CXXFLAGS) ..\..\src\msw\gsocket.cpp
|
||||
|
||||
$(OBJS)\netlib_sockmsw.obj: ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(NETLIB_CXXFLAGS) ..\..\src\msw\sockmsw.cpp
|
||||
|
||||
|
@@ -3497,7 +3497,6 @@ MONODLL_OBJECTS = &
|
||||
$(OBJS)\monodll_sckstrm.obj &
|
||||
$(OBJS)\monodll_socket.obj &
|
||||
$(OBJS)\monodll_url.obj &
|
||||
$(OBJS)\monodll_gsocket.obj &
|
||||
$(OBJS)\monodll_sockmsw.obj &
|
||||
$(OBJS)\monodll_urlmsw.obj &
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_OBJECTS) &
|
||||
@@ -3636,7 +3635,6 @@ MONOLIB_OBJECTS = &
|
||||
$(OBJS)\monolib_sckstrm.obj &
|
||||
$(OBJS)\monolib_socket.obj &
|
||||
$(OBJS)\monolib_url.obj &
|
||||
$(OBJS)\monolib_gsocket.obj &
|
||||
$(OBJS)\monolib_sockmsw.obj &
|
||||
$(OBJS)\monolib_urlmsw.obj &
|
||||
$(____MONOLIB_GUI_SRC_FILENAMES_1_OBJECTS) &
|
||||
@@ -3904,7 +3902,6 @@ NETDLL_OBJECTS = &
|
||||
$(OBJS)\netdll_sckstrm.obj &
|
||||
$(OBJS)\netdll_socket.obj &
|
||||
$(OBJS)\netdll_url.obj &
|
||||
$(OBJS)\netdll_gsocket.obj &
|
||||
$(OBJS)\netdll_sockmsw.obj &
|
||||
$(OBJS)\netdll_urlmsw.obj
|
||||
NETLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
|
||||
@@ -3927,7 +3924,6 @@ NETLIB_OBJECTS = &
|
||||
$(OBJS)\netlib_sckstrm.obj &
|
||||
$(OBJS)\netlib_socket.obj &
|
||||
$(OBJS)\netlib_url.obj &
|
||||
$(OBJS)\netlib_gsocket.obj &
|
||||
$(OBJS)\netlib_sockmsw.obj &
|
||||
$(OBJS)\netlib_urlmsw.obj
|
||||
COREDLL_CXXFLAGS = -bd $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
|
||||
@@ -6114,9 +6110,6 @@ $(OBJS)\monodll_socket.obj : .AUTODEPEND ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monodll_url.obj : .AUTODEPEND ..\..\src\common\url.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\monodll_gsocket.obj : .AUTODEPEND ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\monodll_sockmsw.obj : .AUTODEPEND ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
|
||||
|
||||
@@ -8442,9 +8435,6 @@ $(OBJS)\monolib_socket.obj : .AUTODEPEND ..\..\src\common\socket.cpp
|
||||
$(OBJS)\monolib_url.obj : .AUTODEPEND ..\..\src\common\url.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\monolib_gsocket.obj : .AUTODEPEND ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\monolib_sockmsw.obj : .AUTODEPEND ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
|
||||
|
||||
@@ -11085,9 +11075,6 @@ $(OBJS)\netdll_socket.obj : .AUTODEPEND ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netdll_url.obj : .AUTODEPEND ..\..\src\common\url.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETDLL_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\netdll_gsocket.obj : .AUTODEPEND ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETDLL_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\netdll_sockmsw.obj : .AUTODEPEND ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETDLL_CXXFLAGS) $<
|
||||
|
||||
@@ -11127,9 +11114,6 @@ $(OBJS)\netlib_socket.obj : .AUTODEPEND ..\..\src\common\socket.cpp
|
||||
$(OBJS)\netlib_url.obj : .AUTODEPEND ..\..\src\common\url.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETLIB_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\netlib_gsocket.obj : .AUTODEPEND ..\..\src\msw\gsocket.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETLIB_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\netlib_sockmsw.obj : .AUTODEPEND ..\..\src\msw\sockmsw.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(NETLIB_CXXFLAGS) $<
|
||||
|
||||
|
@@ -294,10 +294,6 @@ SOURCE=..\..\src\common\url.cpp
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\msw\gsocket.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\msw\sockmsw.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -601,9 +601,6 @@
|
||||
<Filter
|
||||
Name="MSW Sources"
|
||||
UniqueIdentifier="{D030D8C2-53EE-5B96-8F89-D78157B06140}">
|
||||
<File
|
||||
RelativePath="..\..\src\msw\gsocket.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\msw\sockmsw.cpp">
|
||||
</File>
|
||||
|
@@ -839,10 +839,6 @@
|
||||
Name="MSW Sources"
|
||||
UniqueIdentifier="{D030D8C2-53EE-5B96-8F89-D78157B06140}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\src\msw\gsocket.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\msw\sockmsw.cpp"
|
||||
>
|
||||
|
@@ -835,10 +835,6 @@
|
||||
Name="MSW Sources"
|
||||
UniqueIdentifier="{D030D8C2-53EE-5B96-8F89-D78157B06140}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\src\msw\gsocket.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\msw\sockmsw.cpp"
|
||||
>
|
||||
|
@@ -1,958 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: wxSocketImpl (Generic Socket)
|
||||
* Name: src/msw/gsocket.cpp
|
||||
* Copyright: (c) Guilhem Lavaux
|
||||
* Licence: wxWindows Licence
|
||||
* Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
||||
* Purpose: wxSocketImpl main MSW file
|
||||
* Licence: The wxWindows licence
|
||||
* CVSID: $Id$
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* RPCNOTIFICATION_ROUTINE in rasasync.h (included from winsock.h),
|
||||
* warning: conditional expression is constant.
|
||||
*/
|
||||
# pragma warning(disable:4115)
|
||||
/* FD_SET,
|
||||
* warning: named type definition in parentheses.
|
||||
*/
|
||||
# pragma warning(disable:4127)
|
||||
/* GAddress_UNIX_GetPath,
|
||||
* warning: unreferenced formal parameter.
|
||||
*/
|
||||
# pragma warning(disable:4100)
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
/* windows.h results in tons of warnings at max warning level */
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(push, 1)
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
# pragma warning(disable:4514)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
//CYGWIN gives annoying warning about runtime stuff if we don't do this
|
||||
# define USE_SYS_TYPES_FD_SET
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <winsock.h>
|
||||
|
||||
#include "wx/platform.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include "wx/private/socket.h"
|
||||
#include "wx/link.h"
|
||||
|
||||
wxFORCE_LINK_MODULE(gsockmsw)
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
#ifndef isdigit
|
||||
#define isdigit(x) (x > 47 && x < 58)
|
||||
#endif
|
||||
#include "wx/msw/wince/net.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "wx/private/socket.h"
|
||||
|
||||
/* static */
|
||||
wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
|
||||
{
|
||||
return new wxSocketImplMSW(wxsocket);
|
||||
}
|
||||
|
||||
void wxSocketImplMSW::DoClose()
|
||||
{
|
||||
wxSocketManager::Get()->
|
||||
Uninstall_Callback(this, wxSOCKET_MAX_EVENT /* unused anyhow */);
|
||||
|
||||
closesocket(m_fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Waits for an incoming client connection. Returns a pointer to
|
||||
* 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 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.
|
||||
*/
|
||||
wxSocketImpl *wxSocketImplMSW::WaitConnection(wxSocketBase& wxsocket)
|
||||
{
|
||||
wxSocketImpl *connection;
|
||||
wxSockAddr from;
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
wxSocketError err;
|
||||
u_long arg = 1;
|
||||
|
||||
/* Reenable CONNECTION events */
|
||||
m_detected &= ~wxSOCKET_CONNECTION_FLAG;
|
||||
|
||||
/* If the socket has already been created, we exit immediately */
|
||||
if (m_fd == INVALID_SOCKET || !m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create a wxSocketImpl object for the new connection */
|
||||
connection = wxSocketImplMSW::Create(wxsocket);
|
||||
|
||||
if (!connection)
|
||||
{
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Wait for a connection (with timeout) */
|
||||
if (Input_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
{
|
||||
delete connection;
|
||||
/* m_error set by Input_Timeout */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
connection->m_fd = accept(m_fd, (sockaddr*)&from, &fromlen);
|
||||
|
||||
if (connection->m_fd == INVALID_SOCKET)
|
||||
{
|
||||
if (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_WOULDBLOCK;
|
||||
else
|
||||
m_error = wxSOCKET_IOERR;
|
||||
|
||||
delete connection;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize all fields */
|
||||
connection->m_server = false;
|
||||
connection->m_stream = true;
|
||||
|
||||
/* Setup the peer address field */
|
||||
connection->m_peer = GAddress_new();
|
||||
if (!connection->m_peer)
|
||||
{
|
||||
delete connection;
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return NULL;
|
||||
}
|
||||
err = _GAddress_translate_from(connection->m_peer, (sockaddr*)&from, fromlen);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
GAddress_destroy(connection->m_peer);
|
||||
delete connection;
|
||||
m_error = err;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ioctlsocket(connection->m_fd, FIONBIO, (u_long FAR *) &arg);
|
||||
wxSocketManager::Get()->Install_Callback(connection);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
wxSocketError wxSocketImplMSW::DoHandleConnect(int ret)
|
||||
{
|
||||
// TODO: review this
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
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 = wxSOCKET_IOERR;
|
||||
return wxSOCKET_IOERR;
|
||||
}
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/* Generic IO */
|
||||
|
||||
/* Like recv(), send(), ... */
|
||||
int wxSocketImplMSW::Read(void *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Reenable INPUT events */
|
||||
m_detected &= ~wxSOCKET_INPUT_FLAG;
|
||||
|
||||
if (m_fd == INVALID_SOCKET || m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the socket is blocking, wait for data (with a timeout) */
|
||||
if (Input_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the data */
|
||||
if (m_stream)
|
||||
ret = Recv_Stream(buffer, size);
|
||||
else
|
||||
ret = Recv_Dgram(buffer, size);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_IOERR;
|
||||
else
|
||||
m_error = wxSOCKET_WOULDBLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Write(const void *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (m_fd == INVALID_SOCKET || m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the socket is blocking, wait for writability (with a timeout) */
|
||||
if (Output_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
return -1;
|
||||
|
||||
/* Write the data */
|
||||
if (m_stream)
|
||||
ret = Send_Stream(buffer, size);
|
||||
else
|
||||
ret = Send_Dgram(buffer, size);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_IOERR;
|
||||
else
|
||||
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 &= ~wxSOCKET_OUTPUT_FLAG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Internals (IO) */
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until data is available or
|
||||
* until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Input_Timeout()
|
||||
{
|
||||
fd_set readfds;
|
||||
|
||||
if (!m_non_blocking)
|
||||
{
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(m_fd, &readfds);
|
||||
if (select(0, &readfds, NULL, NULL, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until data can be sent without
|
||||
* blocking or until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Output_Timeout()
|
||||
{
|
||||
fd_set writefds;
|
||||
|
||||
if (!m_non_blocking)
|
||||
{
|
||||
FD_ZERO(&writefds);
|
||||
FD_SET(m_fd, &writefds);
|
||||
if (select(0, NULL, &writefds, NULL, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until the connection is
|
||||
* established or fails, or until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Connect_Timeout()
|
||||
{
|
||||
fd_set writefds;
|
||||
fd_set exceptfds;
|
||||
|
||||
FD_ZERO(&writefds);
|
||||
FD_ZERO(&exceptfds);
|
||||
FD_SET(m_fd, &writefds);
|
||||
FD_SET(m_fd, &exceptfds);
|
||||
if (select(0, NULL, &writefds, &exceptfds, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
if (!FD_ISSET(m_fd, &writefds))
|
||||
{
|
||||
m_error = wxSOCKET_IOERR;
|
||||
return wxSOCKET_IOERR;
|
||||
}
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Recv_Stream(void *buffer, int size)
|
||||
{
|
||||
return recv(m_fd, static_cast<char *>(buffer), size, 0);
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Recv_Dgram(void *buffer, int size)
|
||||
{
|
||||
wxSockAddr from;
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
int ret;
|
||||
wxSocketError err;
|
||||
|
||||
ret = recvfrom(m_fd, static_cast<char *>(buffer),
|
||||
size, 0, &from, &fromlen);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
return SOCKET_ERROR;
|
||||
|
||||
/* Translate a system address into a wxSocketImpl address */
|
||||
if (!m_peer)
|
||||
{
|
||||
m_peer = GAddress_new();
|
||||
if (!m_peer)
|
||||
{
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
err = _GAddress_translate_from(m_peer, (sockaddr*)&from, fromlen);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
GAddress_destroy(m_peer);
|
||||
m_peer = NULL;
|
||||
m_error = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Send_Stream(const void *buffer, int size)
|
||||
{
|
||||
return send(m_fd, static_cast<const char *>(buffer), size, 0);
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Send_Dgram(const void *buffer, int size)
|
||||
{
|
||||
struct sockaddr *addr;
|
||||
int len, ret;
|
||||
wxSocketError err;
|
||||
|
||||
if (!m_peer)
|
||||
{
|
||||
m_error = wxSOCKET_INVADDR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = _GAddress_translate_to(m_peer, &addr, &len);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
m_error = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = sendto(m_fd, static_cast<const char *>(buffer), size, 0, addr, len);
|
||||
|
||||
/* Frees memory allocated by _GAddress_translate_to */
|
||||
free(addr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* GAddress
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* CHECK_ADDRESS verifies that the current address family is either
|
||||
* 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 == wxSOCKET_NOFAMILY) \
|
||||
if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR) \
|
||||
return address->m_error; \
|
||||
if (address->m_family != wxSOCKET_##family) \
|
||||
{ \
|
||||
address->m_error = wxSOCKET_INVADDR; \
|
||||
return wxSOCKET_INVADDR; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_ADDRESS_RETVAL(address, family, retval) \
|
||||
{ \
|
||||
if (address->m_family == wxSOCKET_NOFAMILY) \
|
||||
if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR) \
|
||||
return retval; \
|
||||
if (address->m_family != wxSOCKET_##family) \
|
||||
{ \
|
||||
address->m_error = wxSOCKET_INVADDR; \
|
||||
return retval; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
GAddress *GAddress_new()
|
||||
{
|
||||
GAddress *address;
|
||||
|
||||
if ((address = (GAddress *) malloc(sizeof(GAddress))) == NULL)
|
||||
return NULL;
|
||||
|
||||
address->m_family = wxSOCKET_NOFAMILY;
|
||||
address->m_addr = NULL;
|
||||
address->m_len = 0;
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
GAddress *GAddress_copy(GAddress *address)
|
||||
{
|
||||
GAddress *addr2;
|
||||
|
||||
if ((addr2 = (GAddress *) malloc(sizeof(GAddress))) == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(addr2, address, sizeof(GAddress));
|
||||
|
||||
if (address->m_addr)
|
||||
{
|
||||
addr2->m_addr = (struct sockaddr *) malloc(addr2->m_len);
|
||||
if (addr2->m_addr == NULL)
|
||||
{
|
||||
free(addr2);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(addr2->m_addr, address->m_addr, addr2->m_len);
|
||||
}
|
||||
|
||||
return addr2;
|
||||
}
|
||||
|
||||
void GAddress_destroy(GAddress *address)
|
||||
{
|
||||
if (address->m_addr)
|
||||
free(address->m_addr);
|
||||
|
||||
free(address);
|
||||
}
|
||||
|
||||
void GAddress_SetFamily(GAddress *address, GAddressType type)
|
||||
{
|
||||
address->m_family = type;
|
||||
}
|
||||
|
||||
GAddressType GAddress_GetFamily(GAddress *address)
|
||||
{
|
||||
return address->m_family;
|
||||
}
|
||||
|
||||
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 = wxSOCKET_INET;
|
||||
break;
|
||||
case AF_UNIX:
|
||||
address->m_family = wxSOCKET_UNIX;
|
||||
break;
|
||||
#if wxUSE_IPV6
|
||||
case AF_INET6:
|
||||
address->m_family = wxSOCKET_INET6;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
address->m_error = wxSOCKET_INVOP;
|
||||
return wxSOCKET_INVOP;
|
||||
}
|
||||
}
|
||||
|
||||
if (address->m_addr)
|
||||
free(address->m_addr);
|
||||
|
||||
address->m_len = len;
|
||||
address->m_addr = (struct sockaddr *) malloc(len);
|
||||
|
||||
if (address->m_addr == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
memcpy(address->m_addr, addr, len);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError _GAddress_translate_to(GAddress *address,
|
||||
struct sockaddr **addr, int *len)
|
||||
{
|
||||
if (!address->m_addr)
|
||||
{
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
|
||||
memcpy(*addr, address->m_addr, address->m_len);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Internet address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
|
||||
{
|
||||
struct hostent *he;
|
||||
struct in_addr *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
|
||||
|
||||
addr->s_addr = inet_addr(hostname);
|
||||
|
||||
/* If it is a numeric host name, convert it now */
|
||||
if (addr->s_addr == INADDR_NONE)
|
||||
{
|
||||
struct in_addr *array_addr;
|
||||
|
||||
/* It is a real name, we solve it */
|
||||
if ((he = gethostbyname(hostname)) == NULL)
|
||||
{
|
||||
/* addr->s_addr = INADDR_NONE just done by inet_addr() above */
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetAnyAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_ANY);
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetHostAddress(GAddress *address,
|
||||
unsigned long hostaddr)
|
||||
{
|
||||
struct in_addr *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
|
||||
addr->s_addr = htonl(hostaddr);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
|
||||
const char *protocol)
|
||||
{
|
||||
struct servent *se;
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
if (!port)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
se = getservbyname(port, protocol);
|
||||
if (!se)
|
||||
{
|
||||
if (isdigit(port[0]))
|
||||
{
|
||||
int port_int;
|
||||
|
||||
port_int = atoi(port);
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = htons((u_short) port_int);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = se->s_port;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = htons(port);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
|
||||
{
|
||||
struct hostent *he;
|
||||
char *addr_buf;
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr_buf = (char *)&(addr->sin_addr);
|
||||
|
||||
he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
|
||||
if (he == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
strncpy(hostname, he->h_name, sbuf);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
unsigned long GAddress_INET_GetHostAddress(GAddress *address)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS_RETVAL(address, INET, 0);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
|
||||
return ntohl(addr->sin_addr.s_addr);
|
||||
}
|
||||
|
||||
unsigned short GAddress_INET_GetPort(GAddress *address)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS_RETVAL(address, INET, 0);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
return ntohs(addr->sin_port);
|
||||
}
|
||||
|
||||
|
||||
#if wxUSE_IPV6
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Internet IPv6 address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#include "ws2tcpip.h"
|
||||
|
||||
#ifdef __VISUALC__
|
||||
#pragma comment(lib,"ws2_32")
|
||||
#endif // __VISUALC__
|
||||
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
memset(address->m_addr,0,address->m_len);
|
||||
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addrinfo hints;
|
||||
memset( & hints, 0, sizeof( hints ) );
|
||||
hints.ai_family = AF_INET6;
|
||||
addrinfo * info = 0;
|
||||
if ( getaddrinfo( hostname, "0", & hints, & info ) || ! info )
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
memcpy( address->m_addr, info->ai_addr, info->ai_addrlen );
|
||||
freeaddrinfo( info );
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
struct in6_addr addr;
|
||||
memset( & addr, 0, sizeof( addr ) );
|
||||
return GAddress_INET6_SetHostAddress(address, addr);
|
||||
}
|
||||
wxSocketError GAddress_INET6_SetHostAddress(GAddress *address,
|
||||
struct in6_addr hostaddr)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
((struct sockaddr_in6 *)address->m_addr)->sin6_addr = hostaddr;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
|
||||
const char *protocol)
|
||||
{
|
||||
struct servent *se;
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
if (!port)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
se = getservbyname(port, protocol);
|
||||
if (!se)
|
||||
{
|
||||
if (isdigit((unsigned char) port[0]))
|
||||
{
|
||||
int port_int;
|
||||
|
||||
port_int = atoi(port);
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = htons((u_short) port_int);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = se->s_port;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = htons(port);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
|
||||
{
|
||||
struct hostent *he;
|
||||
char *addr_buf;
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr_buf = (char *)&(addr->sin6_addr);
|
||||
|
||||
he = gethostbyaddr(addr_buf, sizeof(addr->sin6_addr), AF_INET6);
|
||||
if (he == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
strncpy(hostname, he->h_name, sbuf);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
|
||||
{
|
||||
CHECK_ADDRESS_RETVAL(address, INET6, wxSOCKET_INVADDR);
|
||||
*hostaddr = ( (struct sockaddr_in6 *)address->m_addr )->sin6_addr;
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
unsigned short GAddress_INET6_GetPort(GAddress *address)
|
||||
{
|
||||
CHECK_ADDRESS_RETVAL(address, INET6, 0);
|
||||
|
||||
return ntohs( ((struct sockaddr_in6 *)address->m_addr)->sin6_port );
|
||||
}
|
||||
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Unix address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
wxSocketError _GAddress_Init_UNIX(GAddress *address)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_UNIX_SetPath(GAddress *address, const char *WXUNUSED(path))
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_UNIX_GetPath(GAddress *address, char *WXUNUSED(path), size_t WXUNUSED(sbuf))
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
#endif // wxUSE_SOCKETS
|
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/msw/gsockmsw.cpp
|
||||
// Purpose: MSW-specific socket support
|
||||
// Name: src/msw/sockmsw.cpp
|
||||
// Purpose: MSW-specific socket code
|
||||
// Authors: Guilhem Lavaux, Guillermo Rodriguez Garcia
|
||||
// Created: April 1997
|
||||
// Copyright: (C) 1999-1997, Guilhem Lavaux
|
||||
@@ -20,16 +20,6 @@
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
/*
|
||||
* DONE: for WinCE we need to replace WSAAsyncSelect
|
||||
* (Windows message-based notification of network events for a socket)
|
||||
* with another mechanism.
|
||||
* As WSAAsyncSelect is not present on WinCE, it now uses
|
||||
* WSACreateEvent, WSAEventSelect, WSAWaitForMultipleEvents and WSAEnumNetworkEvents.
|
||||
* When enabling eventhandling for a socket a new thread it created that keeps track of the events
|
||||
* and posts a messageto the hidden window to use the standard message loop.
|
||||
*/
|
||||
|
||||
/* including rasasync.h (included from windows.h itself included from
|
||||
* wx/setup.h and/or winsock.h results in this warning for
|
||||
* RPCNOTIFICATION_ROUTINE
|
||||
@@ -40,27 +30,36 @@
|
||||
|
||||
#include "wx/private/socket.h"
|
||||
#include "wx/apptrait.h"
|
||||
#include "wx/link.h"
|
||||
|
||||
wxFORCE_LINK_THIS_MODULE(gsockmsw)
|
||||
|
||||
extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance();
|
||||
#define INSTANCE wxGetInstance()
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
#include <winsock.h>
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
//CYGWIN gives annoying warning about runtime stuff if we don't do this
|
||||
# define USE_SYS_TYPES_FD_SET
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
/*
|
||||
* As WSAAsyncSelect is not present on WinCE, it now uses WSACreateEvent,
|
||||
* WSAEventSelect, WSAWaitForMultipleEvents and WSAEnumNetworkEvents. When
|
||||
* enabling eventhandling for a socket a new thread it created that keeps track
|
||||
* of the events and posts a messageto the hidden window to use the standard
|
||||
* message loop.
|
||||
*/
|
||||
#include "wx/msw/wince/net.h"
|
||||
#include "wx/hashmap.h"
|
||||
WX_DECLARE_HASH_MAP(int,bool,wxIntegerHash,wxIntegerEqual,SocketHash);
|
||||
|
||||
#ifndef isdigit
|
||||
#define isdigit(x) (x > 47 && x < 58)
|
||||
#endif
|
||||
#include "wx/msw/wince/net.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <winsock.h>
|
||||
#endif // __WXWINCE__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(default:4115) /* named type definition in parentheses */
|
||||
@@ -458,4 +457,886 @@ static struct ManagerSetter
|
||||
}
|
||||
} gs_managerSetter;
|
||||
|
||||
// ============================================================================
|
||||
// wxSocketImpl implementation
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
|
||||
{
|
||||
return new wxSocketImplMSW(wxsocket);
|
||||
}
|
||||
|
||||
void wxSocketImplMSW::DoClose()
|
||||
{
|
||||
wxSocketManager::Get()->
|
||||
Uninstall_Callback(this, wxSOCKET_MAX_EVENT /* unused anyhow */);
|
||||
|
||||
closesocket(m_fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Waits for an incoming client connection. Returns a pointer to
|
||||
* 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 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.
|
||||
*/
|
||||
wxSocketImpl *wxSocketImplMSW::WaitConnection(wxSocketBase& wxsocket)
|
||||
{
|
||||
wxSocketImpl *connection;
|
||||
wxSockAddr from;
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
wxSocketError err;
|
||||
u_long arg = 1;
|
||||
|
||||
/* Reenable CONNECTION events */
|
||||
m_detected &= ~wxSOCKET_CONNECTION_FLAG;
|
||||
|
||||
/* If the socket has already been created, we exit immediately */
|
||||
if (m_fd == INVALID_SOCKET || !m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create a wxSocketImpl object for the new connection */
|
||||
connection = wxSocketImplMSW::Create(wxsocket);
|
||||
|
||||
if (!connection)
|
||||
{
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Wait for a connection (with timeout) */
|
||||
if (Input_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
{
|
||||
delete connection;
|
||||
/* m_error set by Input_Timeout */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
connection->m_fd = accept(m_fd, (sockaddr*)&from, &fromlen);
|
||||
|
||||
if (connection->m_fd == INVALID_SOCKET)
|
||||
{
|
||||
if (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_WOULDBLOCK;
|
||||
else
|
||||
m_error = wxSOCKET_IOERR;
|
||||
|
||||
delete connection;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize all fields */
|
||||
connection->m_server = false;
|
||||
connection->m_stream = true;
|
||||
|
||||
/* Setup the peer address field */
|
||||
connection->m_peer = GAddress_new();
|
||||
if (!connection->m_peer)
|
||||
{
|
||||
delete connection;
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return NULL;
|
||||
}
|
||||
err = _GAddress_translate_from(connection->m_peer, (sockaddr*)&from, fromlen);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
GAddress_destroy(connection->m_peer);
|
||||
delete connection;
|
||||
m_error = err;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ioctlsocket(connection->m_fd, FIONBIO, (u_long FAR *) &arg);
|
||||
wxSocketManager::Get()->Install_Callback(connection);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
wxSocketError wxSocketImplMSW::DoHandleConnect(int ret)
|
||||
{
|
||||
// TODO: review this
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
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 = wxSOCKET_IOERR;
|
||||
return wxSOCKET_IOERR;
|
||||
}
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/* Generic IO */
|
||||
|
||||
/* Like recv(), send(), ... */
|
||||
int wxSocketImplMSW::Read(void *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Reenable INPUT events */
|
||||
m_detected &= ~wxSOCKET_INPUT_FLAG;
|
||||
|
||||
if (m_fd == INVALID_SOCKET || m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the socket is blocking, wait for data (with a timeout) */
|
||||
if (Input_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the data */
|
||||
if (m_stream)
|
||||
ret = Recv_Stream(buffer, size);
|
||||
else
|
||||
ret = Recv_Dgram(buffer, size);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_IOERR;
|
||||
else
|
||||
m_error = wxSOCKET_WOULDBLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Write(const void *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (m_fd == INVALID_SOCKET || m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the socket is blocking, wait for writability (with a timeout) */
|
||||
if (Output_Timeout() == wxSOCKET_TIMEDOUT)
|
||||
return -1;
|
||||
|
||||
/* Write the data */
|
||||
if (m_stream)
|
||||
ret = Send_Stream(buffer, size);
|
||||
else
|
||||
ret = Send_Dgram(buffer, size);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
m_error = wxSOCKET_IOERR;
|
||||
else
|
||||
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 &= ~wxSOCKET_OUTPUT_FLAG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Internals (IO) */
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until data is available or
|
||||
* until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Input_Timeout()
|
||||
{
|
||||
fd_set readfds;
|
||||
|
||||
if (!m_non_blocking)
|
||||
{
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(m_fd, &readfds);
|
||||
if (select(0, &readfds, NULL, NULL, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until data can be sent without
|
||||
* blocking or until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Output_Timeout()
|
||||
{
|
||||
fd_set writefds;
|
||||
|
||||
if (!m_non_blocking)
|
||||
{
|
||||
FD_ZERO(&writefds);
|
||||
FD_SET(m_fd, &writefds);
|
||||
if (select(0, NULL, &writefds, NULL, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* For blocking sockets, wait until the connection is
|
||||
* established or fails, or until timeout ellapses.
|
||||
*/
|
||||
wxSocketError wxSocketImplMSW::Connect_Timeout()
|
||||
{
|
||||
fd_set writefds;
|
||||
fd_set exceptfds;
|
||||
|
||||
FD_ZERO(&writefds);
|
||||
FD_ZERO(&exceptfds);
|
||||
FD_SET(m_fd, &writefds);
|
||||
FD_SET(m_fd, &exceptfds);
|
||||
if (select(0, NULL, &writefds, &exceptfds, &m_timeout) == 0)
|
||||
{
|
||||
m_error = wxSOCKET_TIMEDOUT;
|
||||
return wxSOCKET_TIMEDOUT;
|
||||
}
|
||||
if (!FD_ISSET(m_fd, &writefds))
|
||||
{
|
||||
m_error = wxSOCKET_IOERR;
|
||||
return wxSOCKET_IOERR;
|
||||
}
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Recv_Stream(void *buffer, int size)
|
||||
{
|
||||
return recv(m_fd, static_cast<char *>(buffer), size, 0);
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Recv_Dgram(void *buffer, int size)
|
||||
{
|
||||
wxSockAddr from;
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
int ret;
|
||||
wxSocketError err;
|
||||
|
||||
ret = recvfrom(m_fd, static_cast<char *>(buffer),
|
||||
size, 0, &from, &fromlen);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
return SOCKET_ERROR;
|
||||
|
||||
/* Translate a system address into a wxSocketImpl address */
|
||||
if (!m_peer)
|
||||
{
|
||||
m_peer = GAddress_new();
|
||||
if (!m_peer)
|
||||
{
|
||||
m_error = wxSOCKET_MEMERR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
err = _GAddress_translate_from(m_peer, (sockaddr*)&from, fromlen);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
GAddress_destroy(m_peer);
|
||||
m_peer = NULL;
|
||||
m_error = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Send_Stream(const void *buffer, int size)
|
||||
{
|
||||
return send(m_fd, static_cast<const char *>(buffer), size, 0);
|
||||
}
|
||||
|
||||
int wxSocketImplMSW::Send_Dgram(const void *buffer, int size)
|
||||
{
|
||||
struct sockaddr *addr;
|
||||
int len, ret;
|
||||
wxSocketError err;
|
||||
|
||||
if (!m_peer)
|
||||
{
|
||||
m_error = wxSOCKET_INVADDR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = _GAddress_translate_to(m_peer, &addr, &len);
|
||||
if (err != wxSOCKET_NOERROR)
|
||||
{
|
||||
m_error = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = sendto(m_fd, static_cast<const char *>(buffer), size, 0, addr, len);
|
||||
|
||||
/* Frees memory allocated by _GAddress_translate_to */
|
||||
free(addr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* GAddress
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* CHECK_ADDRESS verifies that the current address family is either
|
||||
* 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 == wxSOCKET_NOFAMILY) \
|
||||
if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR) \
|
||||
return address->m_error; \
|
||||
if (address->m_family != wxSOCKET_##family) \
|
||||
{ \
|
||||
address->m_error = wxSOCKET_INVADDR; \
|
||||
return wxSOCKET_INVADDR; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_ADDRESS_RETVAL(address, family, retval) \
|
||||
{ \
|
||||
if (address->m_family == wxSOCKET_NOFAMILY) \
|
||||
if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR) \
|
||||
return retval; \
|
||||
if (address->m_family != wxSOCKET_##family) \
|
||||
{ \
|
||||
address->m_error = wxSOCKET_INVADDR; \
|
||||
return retval; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
GAddress *GAddress_new()
|
||||
{
|
||||
GAddress *address;
|
||||
|
||||
if ((address = (GAddress *) malloc(sizeof(GAddress))) == NULL)
|
||||
return NULL;
|
||||
|
||||
address->m_family = wxSOCKET_NOFAMILY;
|
||||
address->m_addr = NULL;
|
||||
address->m_len = 0;
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
GAddress *GAddress_copy(GAddress *address)
|
||||
{
|
||||
GAddress *addr2;
|
||||
|
||||
if ((addr2 = (GAddress *) malloc(sizeof(GAddress))) == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(addr2, address, sizeof(GAddress));
|
||||
|
||||
if (address->m_addr)
|
||||
{
|
||||
addr2->m_addr = (struct sockaddr *) malloc(addr2->m_len);
|
||||
if (addr2->m_addr == NULL)
|
||||
{
|
||||
free(addr2);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(addr2->m_addr, address->m_addr, addr2->m_len);
|
||||
}
|
||||
|
||||
return addr2;
|
||||
}
|
||||
|
||||
void GAddress_destroy(GAddress *address)
|
||||
{
|
||||
if (address->m_addr)
|
||||
free(address->m_addr);
|
||||
|
||||
free(address);
|
||||
}
|
||||
|
||||
void GAddress_SetFamily(GAddress *address, GAddressType type)
|
||||
{
|
||||
address->m_family = type;
|
||||
}
|
||||
|
||||
GAddressType GAddress_GetFamily(GAddress *address)
|
||||
{
|
||||
return address->m_family;
|
||||
}
|
||||
|
||||
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 = wxSOCKET_INET;
|
||||
break;
|
||||
case AF_UNIX:
|
||||
address->m_family = wxSOCKET_UNIX;
|
||||
break;
|
||||
#if wxUSE_IPV6
|
||||
case AF_INET6:
|
||||
address->m_family = wxSOCKET_INET6;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
address->m_error = wxSOCKET_INVOP;
|
||||
return wxSOCKET_INVOP;
|
||||
}
|
||||
}
|
||||
|
||||
if (address->m_addr)
|
||||
free(address->m_addr);
|
||||
|
||||
address->m_len = len;
|
||||
address->m_addr = (struct sockaddr *) malloc(len);
|
||||
|
||||
if (address->m_addr == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
memcpy(address->m_addr, addr, len);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError _GAddress_translate_to(GAddress *address,
|
||||
struct sockaddr **addr, int *len)
|
||||
{
|
||||
if (!address->m_addr)
|
||||
{
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
|
||||
memcpy(*addr, address->m_addr, address->m_len);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Internet address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
|
||||
{
|
||||
struct hostent *he;
|
||||
struct in_addr *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
|
||||
|
||||
addr->s_addr = inet_addr(hostname);
|
||||
|
||||
/* If it is a numeric host name, convert it now */
|
||||
if (addr->s_addr == INADDR_NONE)
|
||||
{
|
||||
struct in_addr *array_addr;
|
||||
|
||||
/* It is a real name, we solve it */
|
||||
if ((he = gethostbyname(hostname)) == NULL)
|
||||
{
|
||||
/* addr->s_addr = INADDR_NONE just done by inet_addr() above */
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetAnyAddress(GAddress *address)
|
||||
{
|
||||
return GAddress_INET_SetHostAddress(address, INADDR_ANY);
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetHostAddress(GAddress *address,
|
||||
unsigned long hostaddr)
|
||||
{
|
||||
struct in_addr *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
|
||||
addr->s_addr = htonl(hostaddr);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
|
||||
const char *protocol)
|
||||
{
|
||||
struct servent *se;
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
if (!port)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
se = getservbyname(port, protocol);
|
||||
if (!se)
|
||||
{
|
||||
if (isdigit(port[0]))
|
||||
{
|
||||
int port_int;
|
||||
|
||||
port_int = atoi(port);
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = htons((u_short) port_int);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = se->s_port;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr->sin_port = htons(port);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
|
||||
{
|
||||
struct hostent *he;
|
||||
char *addr_buf;
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
addr_buf = (char *)&(addr->sin_addr);
|
||||
|
||||
he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
|
||||
if (he == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
strncpy(hostname, he->h_name, sbuf);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
unsigned long GAddress_INET_GetHostAddress(GAddress *address)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS_RETVAL(address, INET, 0);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
|
||||
return ntohl(addr->sin_addr.s_addr);
|
||||
}
|
||||
|
||||
unsigned short GAddress_INET_GetPort(GAddress *address)
|
||||
{
|
||||
struct sockaddr_in *addr;
|
||||
|
||||
CHECK_ADDRESS_RETVAL(address, INET, 0);
|
||||
|
||||
addr = (struct sockaddr_in *)address->m_addr;
|
||||
return ntohs(addr->sin_port);
|
||||
}
|
||||
|
||||
|
||||
#if wxUSE_IPV6
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Internet IPv6 address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#include "ws2tcpip.h"
|
||||
|
||||
#ifdef __VISUALC__
|
||||
#pragma comment(lib,"ws2_32")
|
||||
#endif // __VISUALC__
|
||||
|
||||
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 = wxSOCKET_MEMERR;
|
||||
return wxSOCKET_MEMERR;
|
||||
}
|
||||
memset(address->m_addr,0,address->m_len);
|
||||
|
||||
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 wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addrinfo hints;
|
||||
memset( & hints, 0, sizeof( hints ) );
|
||||
hints.ai_family = AF_INET6;
|
||||
addrinfo * info = 0;
|
||||
if ( getaddrinfo( hostname, "0", & hints, & info ) || ! info )
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
memcpy( address->m_addr, info->ai_addr, info->ai_addrlen );
|
||||
freeaddrinfo( info );
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
struct in6_addr addr;
|
||||
memset( & addr, 0, sizeof( addr ) );
|
||||
return GAddress_INET6_SetHostAddress(address, addr);
|
||||
}
|
||||
wxSocketError GAddress_INET6_SetHostAddress(GAddress *address,
|
||||
struct in6_addr hostaddr)
|
||||
{
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
((struct sockaddr_in6 *)address->m_addr)->sin6_addr = hostaddr;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
|
||||
const char *protocol)
|
||||
{
|
||||
struct servent *se;
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
if (!port)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
se = getservbyname(port, protocol);
|
||||
if (!se)
|
||||
{
|
||||
if (isdigit((unsigned char) port[0]))
|
||||
{
|
||||
int port_int;
|
||||
|
||||
port_int = atoi(port);
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = htons((u_short) port_int);
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
address->m_error = wxSOCKET_INVPORT;
|
||||
return wxSOCKET_INVPORT;
|
||||
}
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = se->s_port;
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr->sin6_port = htons(port);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
|
||||
{
|
||||
struct hostent *he;
|
||||
char *addr_buf;
|
||||
struct sockaddr_in6 *addr;
|
||||
|
||||
CHECK_ADDRESS(address, INET6);
|
||||
|
||||
addr = (struct sockaddr_in6 *)address->m_addr;
|
||||
addr_buf = (char *)&(addr->sin6_addr);
|
||||
|
||||
he = gethostbyaddr(addr_buf, sizeof(addr->sin6_addr), AF_INET6);
|
||||
if (he == NULL)
|
||||
{
|
||||
address->m_error = wxSOCKET_NOHOST;
|
||||
return wxSOCKET_NOHOST;
|
||||
}
|
||||
|
||||
strncpy(hostname, he->h_name, sbuf);
|
||||
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
|
||||
{
|
||||
CHECK_ADDRESS_RETVAL(address, INET6, wxSOCKET_INVADDR);
|
||||
*hostaddr = ( (struct sockaddr_in6 *)address->m_addr )->sin6_addr;
|
||||
return wxSOCKET_NOERROR;
|
||||
}
|
||||
|
||||
unsigned short GAddress_INET6_GetPort(GAddress *address)
|
||||
{
|
||||
CHECK_ADDRESS_RETVAL(address, INET6, 0);
|
||||
|
||||
return ntohs( ((struct sockaddr_in6 *)address->m_addr)->sin6_port );
|
||||
}
|
||||
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* Unix address family
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
wxSocketError _GAddress_Init_UNIX(GAddress *address)
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_UNIX_SetPath(GAddress *address, const char *WXUNUSED(path))
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
wxSocketError GAddress_UNIX_GetPath(GAddress *address, char *WXUNUSED(path), size_t WXUNUSED(sbuf))
|
||||
{
|
||||
address->m_error = wxSOCKET_INVADDR;
|
||||
return wxSOCKET_INVADDR;
|
||||
}
|
||||
|
||||
#endif // wxUSE_SOCKETS
|
||||
|
Reference in New Issue
Block a user