Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LionNatsu committed Jul 18, 2014
1 parent b047289 commit 0f30ceb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
13 changes: 9 additions & 4 deletions CLionet.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions CLionet.bi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions CLionet.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
40 changes: 17 additions & 23 deletions Lionet.bas
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
#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
boku->recv(@p,50)
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"
Expand Down

0 comments on commit 0f30ceb

Please sign in to comment.