Skip to content
Permalink
Browse files

Merge pull request #96 from polserver/network-improvements

Network improvements
  • Loading branch information...
frozenblit committed Aug 26, 2019
2 parents 691d330 + ff9f415 commit 71c169e69e671586388e4e204f6f216c643f5408
@@ -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>
@@ -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;
}
}
}
@@ -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
@@ -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 );
};
@@ -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;
}
@@ -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;

0 comments on commit 71c169e

Please sign in to comment.
You can’t perform that action at this time.