Fix white screen of death in remotedesktop

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
DarkmatterVale 2016-01-01 13:08:10 +00:00 committed by Adrien Destugues
parent b23cb01e7c
commit 8de8a927ee
2 changed files with 30 additions and 5 deletions

View File

@ -75,6 +75,7 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
fReceiveBuffer = new(std::nothrow) StreamingRingBuffer(16 * 1024);
if (fReceiveBuffer == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -85,6 +86,7 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
fSendBuffer = new(std::nothrow) StreamingRingBuffer(16 * 1024);
if (fSendBuffer == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -95,6 +97,7 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
fReceiveEndpoint = new(std::nothrow) BNetEndpoint();
if (fReceiveEndpoint == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -105,18 +108,21 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
fReceiver = new(std::nothrow) NetReceiver(fReceiveEndpoint, fReceiveBuffer);
if (fReceiver == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
fSendEndpoint = new(std::nothrow) BNetEndpoint();
if (fSendEndpoint == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
fSender = new(std::nothrow) NetSender(fSendEndpoint, fSendBuffer);
if (fSender == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -125,6 +131,7 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
B_RGB32);
if (fOffscreenBitmap == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -132,6 +139,7 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
B_FOLLOW_NONE, B_WILL_DRAW);
if (fOffscreen == NULL) {
fInitStatus = B_NO_MEMORY;
TRACE_ERROR("no memory available\n");
return;
}
@ -142,6 +150,10 @@ RemoteView::RemoteView(BRect frame, uint16 listenPort)
this);
if (fDrawThread < 0) {
fInitStatus = fDrawThread;
TRACE_ERROR("failed to start _DrawThread()\n");
TRACE_ERROR("status = %" B_PRIx32 "\n", fInitStatus);
return;
}
@ -438,10 +450,15 @@ RemoteView::_DrawThread()
while (!fStopThread) {
uint16 code;
status_t status = message.NextMessage(code);
if (status != B_OK) {
if (status == B_TIMED_OUT || status == -1) {
TRACE_ERROR("could not connect to device\n");
} else {
TRACE_ERROR("failed to read message from receiver\n");
break;
}
}
TRACE("code %u with %ld bytes data\n", code, message.DataLeft());

View File

@ -7,6 +7,7 @@
*/
#include "NetReceiver.h"
#include "RemoteMessage.h"
#include "StreamingRingBuffer.h"
@ -59,16 +60,21 @@ NetReceiver::_NetworkReceiverEntry(void *data)
status_t
NetReceiver::_NetworkReceiver()
{
static const uint16_t shutdown_message[] = { RP_CLOSE_CONNECTION, 0, 0 };
status_t result = fListener->Listen();
if (result != B_OK) {
TRACE_ERROR("failed to listen on port: %s\n", strerror(result));
fTarget->Write(shutdown_message, sizeof(shutdown_message));
return result;
}
while (!fStopThread) {
fEndpoint = fListener->Accept(1000);
if (fEndpoint == NULL)
continue;
fEndpoint = fListener->Accept(5000);
if (fEndpoint == NULL) {
fTarget->Write(shutdown_message, sizeof(shutdown_message));
return B_ERROR;
}
int32 errorCount = 0;
TRACE("new endpoint connection: %p\n", fEndpoint);
@ -81,6 +87,7 @@ NetReceiver::_NetworkReceiver()
BNetEndpoint *endpoint = fEndpoint;
fEndpoint = NULL;
delete endpoint;
fTarget->Write(shutdown_message, sizeof(shutdown_message));
return readSize;
}
@ -101,6 +108,7 @@ NetReceiver::_NetworkReceiver()
if (result != B_OK) {
TRACE_ERROR("writing to ring buffer failed: %s\n",
strerror(result));
fTarget->Write(shutdown_message, sizeof(shutdown_message));
return result;
}
}