diff --git a/makefile b/makefile index e5644e4..a363c12 100644 --- a/makefile +++ b/makefile @@ -82,6 +82,29 @@ # gmake freebsd ARCHID=31 # Reserved for FreeBSD x86 32 bit +# +# Required build switches: +# ARCHID Architecture ID +# +# +# Optional build switches: +# DEBUG 0 = Release, 1 = DEBUG => Default is Release +# FSWATCH_DISABLE 1 = Remove fswatchter support => Default is fswatcher supported +# IPADDR_MONITOR_DISABLE 1 = No IPAddress Monitoring => Default is IPAddress Monitoring Enabled +# IFADDR_DISABLE 1 = Don't use ifaddrs.h => Default is use IFADDR +# KVM 1 = KVM Enabled, 0 = KVM Disabled => Default depends on ARCHID +# KVM_ALL_TILES 0 = Normal, 1 = All Tiles => Default is Normal Tiling Algorithm +# LEGACY_LD 0 = Standard, 1 = Legacy => Default is Standard (CentOS 5.11 requires Legacy) +# NET_SEND_FORCE_FRAGMENT 1 = net.send() fragments sends => Default is normal send operation +# NOTLS 1 = TLS Support Compiled Out => Default is TLS Support Compiled In +# NOTURBOJPEG 1 = Don't use Turbo JPEG => Default is USE TurboJPEG +# SSL_EXPORTABLE_KEYS 1 = Export SSL Keys for debugging => Default is DO NOT export SSL keys +# TLS_WRITE_TRACE 1 = Enable TLS Send Tracing => Default is tracing disabled +# WatchDog WatchDog timer interval. => Default is 6000000 +# WEBLOG 1 = Enable WebLogging Interface => Default is disabled +# WEBRTCDEBUG 1 = Enable WebRTC Instrumentation => Default is disabled +# + # Microstack & Microscript SOURCES = microstack/ILibAsyncServerSocket.c microstack/ILibAsyncSocket.c microstack/ILibAsyncUDPSocket.c microstack/ILibParsers.c microstack/ILibMulticastSocket.c SOURCES += microstack/ILibRemoteLogging.c microstack/ILibWebClient.c microstack/ILibWebRTC.c microstack/ILibWebServer.c microstack/ILibCrypto.c @@ -390,6 +413,15 @@ ifeq ($(TLS_WRITE_TRACE),1) CFLAGS += -D_TLSLOG endif +ifeq ($(NET_SEND_FORCE_FRAGMENT),1) +CFLAGS += -D_DEBUG_NET_FRAGMENT_SEND +endif + +ifeq ($(KVM_ALL_TILES),1) +CFLAGS += -DKVM_ALL_TILES +endif + + GCCTEST := $(shell $(CC) meshcore/dummy.c -o /dev/null -no-pie > /dev/null 2>&1 ; echo $$? ) ifeq ($(GCCTEST),0) LDFLAGS += -no-pie diff --git a/meshcore/KVM/Linux/linux_kvm.c b/meshcore/KVM/Linux/linux_kvm.c index da4c5a1..7a0ad08 100644 --- a/meshcore/KVM/Linux/linux_kvm.c +++ b/meshcore/KVM/Linux/linux_kvm.c @@ -899,9 +899,14 @@ void* kvm_server_mainloop(void* parm) } ILibQueue_UnLock(g_messageQ); - for (r = 0; r < TILE_HEIGHT_COUNT; r++) { - for (c = 0; c < TILE_WIDTH_COUNT; c++) { + for (r = 0; r < TILE_HEIGHT_COUNT; r++) + { + for (c = 0; c < TILE_WIDTH_COUNT; c++) + { g_tileInfo[r][c].flag = TILE_TODO; +#ifdef KVM_ALL_TILES + g_tileInfo[r][c].crc = 0xFF; +#endif } } //fprintf(logFile, "Before CheckDesktopSwitch.\n"); fflush(logFile); diff --git a/meshcore/KVM/MacOS/mac_kvm.c b/meshcore/KVM/MacOS/mac_kvm.c index f9ec402..6a7529c 100644 --- a/meshcore/KVM/MacOS/mac_kvm.c +++ b/meshcore/KVM/MacOS/mac_kvm.c @@ -28,6 +28,12 @@ limitations under the License. int KVM_Listener_FD = -1; #define KVM_Listener_Path "/usr/local/mesh_services/meshagent/kvm" +#if defined(_TLSLOG) +#define TLSLOG1 printf +#else +#define TLSLOG1(...) ; +#endif + int KVM_AGENT_FD = -1; int KVM_SEND(char *buffer, int bufferLen) @@ -488,12 +494,17 @@ void* kvm_server_mainloop(void* param) ILibQueue_UnLock(g_messageQ); - for (r = 0; r < TILE_HEIGHT_COUNT; r++) { - for (c = 0; c < TILE_WIDTH_COUNT; c++) { + for (r = 0; r < TILE_HEIGHT_COUNT; r++) + { + for (c = 0; c < TILE_WIDTH_COUNT; c++) + { g_tileInfo[r][c].flag = TILE_TODO; +#ifdef KVM_ALL_TILES + g_tileInfo[r][c].crc = 0xFF; +#endif } } - //senddebug(2); + screen_num = CGMainDisplayID(); if (screen_num == 0) { g_shutdown = 1; senddebug(-2); break; } @@ -538,8 +549,6 @@ void* kvm_server_mainloop(void* param) fsync(STDOUT_FILENO); } - - for (y = 0; y < TILE_HEIGHT_COUNT; y++) { for (x = 0; x < TILE_WIDTH_COUNT; x++) { @@ -642,7 +651,9 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1]))) { *bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]); + TLSLOG1("<< KVM/WRITE: %d bytes\n", *bytesConsumed); writeHandler(buffer, *bytesConsumed, reserved); + //printf("JUMBO PACKET: %d\n", *bytesConsumed); return; } diff --git a/meshcore/KVM/MacOS/mac_tile.c b/meshcore/KVM/MacOS/mac_tile.c index 8d9dce3..b35687f 100644 --- a/meshcore/KVM/MacOS/mac_tile.c +++ b/meshcore/KVM/MacOS/mac_tile.c @@ -325,11 +325,12 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop, } int retval = 0; - int firstTime = 1; #if MAX_TILE_SIZE == 0 retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize); #else + int firstTime = 1; + //This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time. do { //retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent. @@ -389,7 +390,8 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop, jpeg_buffer_length = 0; for (r = row; r <= botrow; r++) { - for (c = col; c <= rightcol; c++) { + for (c = col; c <= rightcol; c++) + { g_tileInfo[r][c].flag = TILE_SENT; } } diff --git a/meshcore/KVM/Windows/kvm.c b/meshcore/KVM/Windows/kvm.c index 517b430..e548063 100644 --- a/meshcore/KVM/Windows/kvm.c +++ b/meshcore/KVM/Windows/kvm.c @@ -901,9 +901,14 @@ DWORD WINAPI kvm_server_mainloop_ex(LPVOID parm) KVMDEBUG("kvm_server_mainloop / loop1", (int)GetCurrentThreadId()); // Reset all the flags to TILE_TODO - for (row = 0; row < TILE_HEIGHT_COUNT; row++) { - for (col = 0; col < TILE_WIDTH_COUNT; col++) { + for (row = 0; row < TILE_HEIGHT_COUNT; row++) + { + for (col = 0; col < TILE_WIDTH_COUNT; col++) + { tileInfo[row][col].flags = (char)TILE_TODO; +#ifdef KVM_ALL_TILES + tileInfo[row][col].crc = 0xFF; +#endif } } CheckDesktopSwitch(1, writeHandler, reserved); diff --git a/microscript/ILibDuktape_net.c b/microscript/ILibDuktape_net.c index 7c42790..da162c8 100644 --- a/microscript/ILibDuktape_net.c +++ b/microscript/ILibDuktape_net.c @@ -251,7 +251,15 @@ void ILibDuktape_net_socket_OnSendOK(ILibAsyncSocket_SocketModule socketModule, ILibTransport_DoneState ILibDuktape_net_socket_WriteHandler(ILibDuktape_DuplexStream *stream, char *buffer, int bufferLen, void *user) { ILibDuktape_net_socket *ptrs = (ILibDuktape_net_socket*)user; +#ifdef _DEBUG_NET_FRAGMENT_SEND + int x = bufferLen / 2; + printf("** Send 1/2: %d of %d bytes\n", x, bufferLen); + ILibAsyncSocket_Send(ptrs->socketModule, buffer, x, ILibAsyncSocket_MemoryOwnership_USER); + printf("** Send 2/2: %d of %d bytes\n", bufferLen - x, bufferLen); + return((ILibTransport_DoneState)ILibAsyncSocket_Send(ptrs->socketModule, buffer + x, bufferLen - x, ILibAsyncSocket_MemoryOwnership_USER)); +#else return((ILibTransport_DoneState)ILibAsyncSocket_Send(ptrs->socketModule, buffer, bufferLen, ILibAsyncSocket_MemoryOwnership_USER)); +#endif } void ILibDuktape_net_socket_EndHandler(ILibDuktape_DuplexStream *stream, void *user) { diff --git a/microstack/ILibAsyncSocket.c b/microstack/ILibAsyncSocket.c index 3b1877c..92b4325 100644 --- a/microstack/ILibAsyncSocket.c +++ b/microstack/ILibAsyncSocket.c @@ -606,6 +606,10 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc ignore_result(BIO_reset(module->writeBio)); } + else if (bytesSent < 0) + { + TLSLOG1(" -- > [INCOMPLETE] Accumulated into BIOBUFFER[%d]\n", module->internalSocket); + } retVal = ILibAsyncSocket_NOT_ALL_DATA_SENT_YET; } else if (bytesSent == module->writeBioBuffer->length) @@ -634,7 +638,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc // Send will happen in ILibAsyncSocket_PostSelect() retVal = ILibAsyncSocket_NOT_ALL_DATA_SENT_YET; module->PendingBytesToSend = (unsigned int)(module->writeBioBuffer->length); - TLSLOG1(" --> Accumulate[%d]...\n", module->internalSocket); + TLSLOG1(" --> [IN PROGRESS] Accumulated into BIOBUFFER[%d]...\n", module->internalSocket); } if (lockOverride == 0) { sem_post(&(module->SendLock)); } @@ -1883,7 +1887,14 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f } else { - TLSLOG1(" --> REMAINING: %d bytes --<\n", module->PendingSend_Head->bufferSize - module->PendingSend_Head->bytesSent); + if (module->PendingSend_Head->bufferSize - module->PendingSend_Head->bytesSent == 0 && module->PendingSend_Head->UserFree == ILibAsyncSocket_MemoryOwnership_BIO) + { + TLSLOG1(" --> DRAINED (BIOBUFFER still has %d bytes)\n", (int)(module->writeBioBuffer->length)); + } + else + { + TLSLOG1(" --> REMAINING: %d bytes --<\n", module->PendingSend_Head->bufferSize - module->PendingSend_Head->bytesSent); + } } } if (bytesSent <= 0) @@ -1901,7 +1912,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f { BIO_clear_retry_flags(module->writeBio); bytesSent = (int)send(module->internalSocket, module->writeBioBuffer->data, (int)(module->writeBioBuffer->length), MSG_NOSIGNAL); // Klocwork reports that this could block while holding a lock... This socket has been set to O_NONBLOCK, so that will never happen - TLSLOG1(" << Accumulated Drain[%d]: %d bytes >>\n", module->internalSocket, bytesSent); + TLSLOG1(" << BIOBUFFER[%d] drain: %d of %d bytes >>\n", module->internalSocket, bytesSent, (int)module->writeBioBuffer->length); #ifdef WIN32 if ((bytesSent > 0 && bytesSent < (int)(module->writeBioBuffer->length)) || (bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK)) #else @@ -1914,8 +1925,8 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f module->PendingSend_Head->UserFree = ILibAsyncSocket_MemoryOwnership_CHAIN; module->PendingSend_Head->buffer = ILibMemory_Allocate((int)module->writeBioBuffer->length - bytesSent, 0, NULL, NULL); module->PendingSend_Head->bufferSize = (int)module->writeBioBuffer->length - bytesSent; - module->PendingSend_Head->bytesSent = 0; - memcpy_s(module->PendingSend_Head->buffer, module->PendingSend_Head->bufferSize, module->writeBioBuffer + bytesSent, module->PendingSend_Head->bufferSize); + module->PendingSend_Head->bytesSent = 0; + memcpy_s(module->PendingSend_Head->buffer, module->PendingSend_Head->bufferSize, module->writeBioBuffer->data + bytesSent, module->PendingSend_Head->bufferSize); TLSLOG1(" <<-- BUFFERING[%d]: %d bytes -->>\n", module->internalSocket, module->PendingSend_Head->bufferSize);