Skip to content

Commit

Permalink
Merge pull request #96 from polserver/network-improvements
Browse files Browse the repository at this point in the history
Network improvements
  • Loading branch information
frozenblit committed Aug 26, 2019
2 parents 691d330 + ff9f415 commit 71c169e
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 209 deletions.
7 changes: 6 additions & 1 deletion docs/docs.polserver.com/pol100/corechanges.xml
Expand Up @@ -2,9 +2,14 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>08-21-2019</datemodified>
<datemodified>08-26-2019</datemodified>
</header>
<version name="POL100">
<entry>
<date>08-26-2019</date>
<author>Nando:</author>
<change type="Changed">Improved how the debug, www and aux servers handle connections. They should be faster and more stable now. Minor issues fixed.</change>
</entry>
<entry>
<date>08-21-2019</date>
<author>DevGIB:</author>
Expand Down
66 changes: 0 additions & 66 deletions pol-core/clib/network/sckutil.cpp
Expand Up @@ -14,77 +14,11 @@ namespace Pol
{
namespace Clib
{
bool readline( Socket& sck, std::string& s, bool* timeout_exit, unsigned int timeout_secs,
unsigned maxlen )
{
if ( timeout_exit )
*timeout_exit = false;
s = "";
unsigned char ch;
unsigned timeouts_left = timeout_secs / 2;
while ( !exit_signalled && sck.connected() )
{
if ( sck.recvbyte( &ch, 2000 ) )
{
timeouts_left = timeout_secs / 2;
if ( isprint( ch ) )
{
s.append( 1, ch );
if ( maxlen && s.length() > maxlen )
{
sck.close();
return false;
}
}
else
{
if ( ch == '\n' )
return true;
}
}
else
{
if ( timeout_secs && !--timeouts_left )
{
if ( timeout_exit )
*timeout_exit = true;
return false;
}
}
}
return false;
}

void writeline( Socket& sck, const std::string& s )
{
sck.send( (void*)s.c_str(), static_cast<unsigned int>( s.length() ) );
sck.send( "\r\n", 2 );
}

bool readstring( Socket& sck, std::string& s, unsigned int interchar_secs, unsigned length )
{
s = "";
unsigned char ch;
unsigned timeouts_left = interchar_secs / 2;
while ( !exit_signalled && sck.connected() )
{
if ( sck.recvbyte( &ch, 2000 ) )
{
timeouts_left = interchar_secs / 2;

s.append( 1, ch );
if ( s.length() == length )
{
return true;
}
}
else
{
if ( !--timeouts_left )
return false;
}
}
return false;
}
}
}
6 changes: 2 additions & 4 deletions pol-core/clib/network/sckutil.h
Expand Up @@ -14,12 +14,10 @@ namespace Clib
{
class Socket;

bool readline( Socket& sck, std::string& s, bool* timeout_exit = 0,
unsigned int interchar_timeout_secs = 0, unsigned maxlen = 0 );

// TODO: move this function into the Socket class
// TODO: get rid of http_writeline, it's doing exactly the same as this function
void writeline( Socket& sck, const std::string& s );

bool readstring( Socket& sck, std::string& s, unsigned int interchar_secs, unsigned length );
}
}
#endif
2 changes: 1 addition & 1 deletion pol-core/clib/network/singlepollers/pollingwithpoll.h
Expand Up @@ -8,7 +8,7 @@
#ifdef _WIN32

// compatibility wrapper for windows
int poll( struct pollfd* fds, ULONG nfds, int timeout )
inline int poll( struct pollfd* fds, ULONG nfds, int timeout )
{
return WSAPoll( fds, nfds, timeout );
};
Expand Down
4 changes: 2 additions & 2 deletions pol-core/clib/network/socketsvc.cpp
Expand Up @@ -36,9 +36,9 @@ SocketListener::SocketListener( unsigned short port, Socket::option opt ) : _lis
}

bool SocketListener::GetConnection( Socket* newsck, unsigned int timeout_sec,
unsigned int timeout_usec )
unsigned int timeout_msec )
{
if ( _listen_sck.select( timeout_sec, timeout_usec ) )
if ( _listen_sck.has_incoming_data( timeout_sec * 1000 + timeout_msec ) )
return _listen_sck.accept( newsck );
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pol-core/clib/network/socketsvc.h
Expand Up @@ -18,7 +18,7 @@ class SocketListener
public:
explicit SocketListener( unsigned short port );
SocketListener( unsigned short port, Socket::option opt );
bool GetConnection( Socket* newsck, unsigned int timeout_sec, unsigned int timeout_usec = 0 );
bool GetConnection( Socket* newsck, unsigned int timeout_sec, unsigned int timeout_msec = 0 );

friend class SocketClientThread;

Expand Down

0 comments on commit 71c169e

Please sign in to comment.