From c22888fa8ecb6e98ed798b8e043af9493e43c9c5 Mon Sep 17 00:00:00 2001
From: DarkmatterVale <valetolpegin@gmail.com>
Date: Fri, 1 Jan 2016 13:08:10 +0000
Subject: [PATCH 2/2] Fix white screen of death in remotedesktop
---
src/apps/remotedesktop/RemoteView.cpp | 21 +++++++++++++++++++--
.../app/drawing/interface/remote/NetReceiver.cpp | 14 +++++++++++---
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/src/apps/remotedesktop/RemoteView.cpp b/src/apps/remotedesktop/RemoteView.cpp
index 0693886..399300a 100644
a
|
b
|
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
75 | 75 | fReceiveBuffer = new(std::nothrow) StreamingRingBuffer(16 * 1024); |
76 | 76 | if (fReceiveBuffer == NULL) { |
77 | 77 | fInitStatus = B_NO_MEMORY; |
| 78 | TRACE_ERROR("no memory available\n"); |
78 | 79 | return; |
79 | 80 | } |
80 | 81 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
85 | 86 | fSendBuffer = new(std::nothrow) StreamingRingBuffer(16 * 1024); |
86 | 87 | if (fSendBuffer == NULL) { |
87 | 88 | fInitStatus = B_NO_MEMORY; |
| 89 | TRACE_ERROR("no memory available\n"); |
88 | 90 | return; |
89 | 91 | } |
90 | 92 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
95 | 97 | fReceiveEndpoint = new(std::nothrow) BNetEndpoint(); |
96 | 98 | if (fReceiveEndpoint == NULL) { |
97 | 99 | fInitStatus = B_NO_MEMORY; |
| 100 | TRACE_ERROR("no memory available\n"); |
98 | 101 | return; |
99 | 102 | } |
100 | 103 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
105 | 108 | fReceiver = new(std::nothrow) NetReceiver(fReceiveEndpoint, fReceiveBuffer); |
106 | 109 | if (fReceiver == NULL) { |
107 | 110 | fInitStatus = B_NO_MEMORY; |
| 111 | TRACE_ERROR("no memory available\n"); |
108 | 112 | return; |
109 | 113 | } |
110 | 114 | |
111 | 115 | fSendEndpoint = new(std::nothrow) BNetEndpoint(); |
112 | 116 | if (fSendEndpoint == NULL) { |
113 | 117 | fInitStatus = B_NO_MEMORY; |
| 118 | TRACE_ERROR("no memory available\n"); |
114 | 119 | return; |
115 | 120 | } |
116 | 121 | |
117 | 122 | fSender = new(std::nothrow) NetSender(fSendEndpoint, fSendBuffer); |
118 | 123 | if (fSender == NULL) { |
119 | 124 | fInitStatus = B_NO_MEMORY; |
| 125 | TRACE_ERROR("no memory available\n"); |
120 | 126 | return; |
121 | 127 | } |
122 | 128 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
125 | 131 | B_RGB32); |
126 | 132 | if (fOffscreenBitmap == NULL) { |
127 | 133 | fInitStatus = B_NO_MEMORY; |
| 134 | TRACE_ERROR("no memory available\n"); |
128 | 135 | return; |
129 | 136 | } |
130 | 137 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
132 | 139 | B_FOLLOW_NONE, B_WILL_DRAW); |
133 | 140 | if (fOffscreen == NULL) { |
134 | 141 | fInitStatus = B_NO_MEMORY; |
| 142 | TRACE_ERROR("no memory available\n"); |
135 | 143 | return; |
136 | 144 | } |
137 | 145 | |
… |
… |
RemoteView::RemoteView(BRect frame, uint16 listenPort)
|
142 | 150 | this); |
143 | 151 | if (fDrawThread < 0) { |
144 | 152 | fInitStatus = fDrawThread; |
| 153 | |
| 154 | TRACE_ERROR("failed to start _DrawThread()\n"); |
| 155 | TRACE_ERROR("status = %" B_PRIx32 "\n", fInitStatus); |
| 156 | |
145 | 157 | return; |
146 | 158 | } |
147 | 159 | |
… |
… |
RemoteView::_DrawThread()
|
438 | 450 | while (!fStopThread) { |
439 | 451 | uint16 code; |
440 | 452 | status_t status = message.NextMessage(code); |
| 453 | |
441 | 454 | if (status != B_OK) { |
442 | | TRACE_ERROR("failed to read message from receiver\n"); |
443 | | break; |
| 455 | if (status == B_TIMED_OUT || status == -1) { |
| 456 | TRACE_ERROR("could not connect to device\n"); |
| 457 | } else { |
| 458 | TRACE_ERROR("failed to read message from receiver\n"); |
| 459 | break; |
| 460 | } |
444 | 461 | } |
445 | 462 | |
446 | 463 | TRACE("code %u with %ld bytes data\n", code, message.DataLeft()); |
diff --git a/src/servers/app/drawing/interface/remote/NetReceiver.cpp b/src/servers/app/drawing/interface/remote/NetReceiver.cpp
index d88fcfa..2b5064d 100644
a
|
b
|
|
7 | 7 | */ |
8 | 8 | |
9 | 9 | #include "NetReceiver.h" |
| 10 | #include "RemoteMessage.h" |
10 | 11 | |
11 | 12 | #include "StreamingRingBuffer.h" |
12 | 13 | |
… |
… |
NetReceiver::_NetworkReceiverEntry(void *data)
|
59 | 60 | status_t |
60 | 61 | NetReceiver::_NetworkReceiver() |
61 | 62 | { |
| 63 | static const uint16_t shutdown_message[] = { RP_CLOSE_CONNECTION, 0, 0 }; |
| 64 | |
62 | 65 | status_t result = fListener->Listen(); |
63 | 66 | if (result != B_OK) { |
64 | 67 | TRACE_ERROR("failed to listen on port: %s\n", strerror(result)); |
| 68 | fTarget->Write(shutdown_message, sizeof(shutdown_message)); |
65 | 69 | return result; |
66 | 70 | } |
67 | 71 | |
68 | 72 | while (!fStopThread) { |
69 | | fEndpoint = fListener->Accept(1000); |
70 | | if (fEndpoint == NULL) |
71 | | continue; |
| 73 | fEndpoint = fListener->Accept(5000); |
| 74 | if (fEndpoint == NULL) { |
| 75 | fTarget->Write(shutdown_message, sizeof(shutdown_message)); |
| 76 | return B_ERROR; |
| 77 | } |
72 | 78 | |
73 | 79 | int32 errorCount = 0; |
74 | 80 | TRACE("new endpoint connection: %p\n", fEndpoint); |
… |
… |
NetReceiver::_NetworkReceiver()
|
81 | 87 | BNetEndpoint *endpoint = fEndpoint; |
82 | 88 | fEndpoint = NULL; |
83 | 89 | delete endpoint; |
| 90 | fTarget->Write(shutdown_message, sizeof(shutdown_message)); |
84 | 91 | return readSize; |
85 | 92 | } |
86 | 93 | |
… |
… |
NetReceiver::_NetworkReceiver()
|
101 | 108 | if (result != B_OK) { |
102 | 109 | TRACE_ERROR("writing to ring buffer failed: %s\n", |
103 | 110 | strerror(result)); |
| 111 | fTarget->Write(shutdown_message, sizeof(shutdown_message)); |
104 | 112 | return result; |
105 | 113 | } |
106 | 114 | } |