diff --git a/CLionet.bas b/CLionet.bas index 2e43115..89be715 100644 --- a/CLionet.bas +++ b/CLionet.bas @@ -47,10 +47,8 @@ function CLionet.eventThread( boku as CLionet ptr ) as integer print "thread" dim as WSANETWORKEVENTS event_info do - print "---#1" if boku->flag_thread = 2 then boku->flag_thread = 0 : exit do if WSAWaitForMultipleEvents( 1, @boku->m_event, -1, 1000, -1 ) = WSA_WAIT_TIMEOUT then continue do - print "---#2",CLionet.error,*CLionet.error_string WSAEnumNetworkEvents( boku->m_socket, boku->m_event, @event_info ) #macro ROUTER( fnc, evtmsk, bitmsk ) if ( event_info.lNetworkEvents and evtmsk ) <> 0 then @@ -67,17 +65,18 @@ function CLionet.eventThread( boku as CLionet ptr ) as integer ROUTER (onWrite,FD_WRITE,FD_WRITE_BIT) ROUTER (onClose,FD_CLOSE,FD_CLOSE_BIT) #undef ROUTER - print "---#3" - sleep_ 1000 + sleep_ 0 loop return 0 end function function CLionet.accept() as integer dim newsocket as SOCKET + this.detachEvent() newsocket = .accept( this.m_socket, null, null ) this.closesocket() this.m_socket = newsocket + this.attachEvent() return this.m_socket end function @@ -86,8 +85,10 @@ function CLionet.accept( scklistener as CLionet ptr ) as integer end function function CLionet.accept( scklistener as SOCKET ) as integer + this.detachEvent() this.closesocket() this.m_socket = .accept( scklistener, null, null ) + this.attachEvent() return this.m_socket end function @@ -201,6 +202,10 @@ property CLionet.async() as CLIONET_MODE return this.async_mode end property +sub CLionet.exitEventThread() + ExitThread( 0 ) +end sub + sub CLionet.attachEvent() if this.async_mode <> CLIONET_MODE.CLAM_EVENTSELECT then exit sub WSAEventSelect( this.m_socket, this.m_event, FD_READ or FD_CLOSE or FD_CONNECT or FD_ACCEPT or FD_WRITE ) diff --git a/CLionet.bi b/CLionet.bi index 6d33662..0d5e4d5 100644 --- a/CLionet.bi +++ b/CLionet.bi @@ -20,6 +20,7 @@ type CLionet extends object #else declare static function error_string() as zstring ptr #endif + declare static sub exitEventThread() declare virtual function opensocket() as integer declare virtual function closesocket() as integer declare virtual function connect( addr as string, port as ushort ) as integer diff --git a/CLionet.fbp b/CLionet.fbp index 81e2af8..62d6730 100644 --- a/CLionet.fbp +++ b/CLionet.fbp @@ -10,7 +10,7 @@ CompileIfNewer=0 IncVersion=0 RunCmd=0 [Make] -Current=2 +Current=1 1=Windows Console (Server),fbc -s console -d __SERVER__ -x "Server.exe" 2=Windows Console (Client),fbc -s console -x "Client.exe" Recompile=2 @@ -34,8 +34,8 @@ Main=1 1001= 4= [FileInfo] -1=0,45,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -2=0,63,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +1=0,32,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +2=0,22,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 3=0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -1001=0,42,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +1001=0,204,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 4=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/Lionet.bas b/Lionet.bas index 00c2f93..8c3bc0e 100644 --- a/Lionet.bas +++ b/Lionet.bas @@ -1,12 +1,8 @@ #ifdef __SERVER__ 'Server #include "CLionet.bi" - -sub Onxxx ( boku as CLionet ptr, msg as integer, errcode as integer ) +sub OnB ( boku as CLionet ptr, msg as integer, errcode as integer ) select case msg - case FD_ACCEPT - print "ACCEPT" - boku->accept() case FD_READ print "READ" dim p as zstring * 50 @@ -14,33 +10,31 @@ sub Onxxx ( boku as CLionet ptr, msg as integer, errcode as integer ) print "data:["& p &"]" case FD_CLOSE print "CLOSE" + boku->async = CLAM_BLOCK boku->closesocket() - boku->opensocket() - boku->listen(85) - print "RE-LISTEN",CLionet.error,*CLionet.error_string + delete boku + CLionet.exitEventThread() + end select +end sub +sub OnA ( boku as CLionet ptr, msg as integer, errcode as integer ) + select case msg + case FD_ACCEPT + print "ACCEPT" + dim as CLionet ptr cc = new CLionet() + cc->onSocket = procptr(OnB) + cc->async = CLAM_EVENTSELECT + cc->accept(boku) end select end sub CLionet.startup() dim as CLionet ptr cl = new CLionet() +cl->onSocket = procptr(OnA) +cl->async = CLAM_EVENTSELECT cl->listen(85) -cl->onSocket = procptr(Onxxx) -cl->async = CLIONET_MODE.CLAM_EVENTSELECT - -do - sleep_ 0 -Loop +do:sleep_ 0:loop end -cl->accept() -dim p as zstring * 50 -cl->recv(@p,50) -print cl->localport -print p -sleep -delete cl -CLionet.cleanup() - #else 'Client #include "CLionet.bi"