Skip to content

Commit 597e70e

Browse files
authored
Merge pull request #2809 from bitshares/release_to_develop
Merge release branch back into develop branch
2 parents fe40983 + 8246be8 commit 597e70e

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

libraries/net/message_oriented_connection.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,20 @@ namespace graphene { namespace net {
172172

173173
fc::oexception exception_to_rethrow;
174174
bool call_on_connection_closed = false;
175+
bool io_error = false;
175176

176177
try
177178
{
178179
message m;
179180
char buffer[BUFFER_SIZE];
180181
while( true )
181182
{
182-
_sock.read(buffer, BUFFER_SIZE);
183+
try {
184+
_sock.read(buffer, BUFFER_SIZE);
185+
} catch ( const fc::canceled_exception& ) {
186+
io_error = true;
187+
throw;
188+
}
183189
_bytes_received += BUFFER_SIZE;
184190
memcpy((char*)&m, buffer, sizeof(message_header));
185191
FC_ASSERT( m.size.value() <= MAX_MESSAGE_SIZE, "", ("m.size",m.size.value())("MAX_MESSAGE_SIZE",MAX_MESSAGE_SIZE) );
@@ -189,7 +195,12 @@ namespace graphene { namespace net {
189195
std::copy(buffer + sizeof(message_header), buffer + sizeof(buffer), m.data.begin());
190196
if (remaining_bytes_with_padding)
191197
{
192-
_sock.read(&m.data[LEFTOVER], remaining_bytes_with_padding);
198+
try {
199+
_sock.read(&m.data[LEFTOVER], remaining_bytes_with_padding);
200+
} catch ( const fc::canceled_exception& ) {
201+
io_error = true;
202+
throw;
203+
}
193204
_bytes_received += remaining_bytes_with_padding;
194205
}
195206
m.data.resize(m.size.value()); // truncate off the padding bytes
@@ -214,8 +225,20 @@ namespace graphene { namespace net {
214225
}
215226
catch ( const fc::canceled_exception& e )
216227
{
217-
wlog( "caught a canceled_exception in read_loop. this should mean we're in the process of deleting this object already, so there's no need to notify the delegate: ${e}", ("e", e.to_detail_string() ) );
218-
throw;
228+
if( io_error )
229+
{
230+
wlog( "disconnected on io error ${e}", ("e", e.to_detail_string() ) );
231+
call_on_connection_closed = true;
232+
exception_to_rethrow = fc::unhandled_exception(FC_LOG_MESSAGE(warn, "disconnected on io error: ${e}",
233+
("e", e.to_detail_string())));
234+
}
235+
else
236+
{
237+
wlog( "caught a canceled_exception in read_loop. this should mean we're in the process of deleting "
238+
"this object already, so there's no need to notify the delegate: ${e}",
239+
("e", e.to_detail_string() ) );
240+
throw;
241+
}
219242
}
220243
catch ( const fc::eof_exception& e )
221244
{

0 commit comments

Comments
 (0)