Skip to content

Commit

Permalink
fix crash on port scan
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Oct 9, 2017
1 parent a490402 commit b1edc34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
6 changes: 4 additions & 2 deletions client/debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ snapclient (0.12.0) unstable; urgency=low
* Bugfixes
-Snapclient: more reliable unique client id (Issue #249)
-Snapserver: fix config file permissions (Issue #251)
-Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238)
-Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238)
-Snapserver: fix crash on port scan (Issue #267)
* General
-Improved logging: Use "--debug" for debug logging
-Log to file: Use "--debug=<filename>"
-Improved exception handling and error logging (Issue #276)
-Android: update to NDK r16 and clang++
-hide spotify credentials in json control message (Issue #282)

-- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200

Expand Down
31 changes: 19 additions & 12 deletions server/controlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,26 @@ void ControlServer::startAccept()

void ControlServer::handleAccept(socket_ptr socket)
{
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
// socket->set_option(boost::asio::ip::tcp::no_delay(false));
SLOG(NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket);
try
{
std::lock_guard<std::recursive_mutex> mlock(mutex_);
session->start();
sessions_.insert(session);
cleanup();
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
// socket->set_option(boost::asio::ip::tcp::no_delay(false));
SLOG(NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket);
{
std::lock_guard<std::recursive_mutex> mlock(mutex_);
session->start();
sessions_.insert(session);
cleanup();
}
}
catch (const std::exception& e)
{
SLOG(ERROR) << "Exception in ControlServer::handleAccept: " << e.what() << endl;
}
startAccept();
}
Expand Down
6 changes: 4 additions & 2 deletions server/debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ snapserver (0.12.0) unstable; urgency=low
* Bugfixes
-Snapclient: more reliable unique client id (Issue #249)
-Snapserver: fix config file permissions (Issue #251)
-Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238)
-Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238)
-Snapserver: fix crash on port scan (Issue #267)
* General
-Improved logging: Use "--debug" for debug logging
-Log to file: Use "--debug=<filename>"
-Improved exception handling and error logging (Issue #276)
-Android: update to NDK r16 and clang++
-hide spotify credentials in json control message (Issue #282)

-- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200

Expand Down
34 changes: 20 additions & 14 deletions server/streamServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,24 +576,30 @@ void StreamServer::startAccept()

void StreamServer::handleAccept(socket_ptr socket)
{
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
try
{
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));

/// experimental: turn on tcp::no_delay
socket->set_option(tcp::no_delay(true));
/// experimental: turn on tcp::no_delay
socket->set_option(tcp::no_delay(true));

SLOG(NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket);
SLOG(NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket);

session->setBufferMs(settings_.bufferMs);
session->start();

std::lock_guard<std::recursive_mutex> mlock(sessionsMutex_);
sessions_.insert(session);
session->setBufferMs(settings_.bufferMs);
session->start();

std::lock_guard<std::recursive_mutex> mlock(sessionsMutex_);
sessions_.insert(session);
}
catch (const std::exception& e)
{
SLOG(ERROR) << "Exception in StreamServer::handleAccept: " << e.what() << endl;
}
startAccept();
}

Expand Down

0 comments on commit b1edc34

Please sign in to comment.