1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-17 00:33:33 +00:00

Removed context switches for sending packets

This commit is contained in:
Bryan Roe
2020-11-21 16:19:14 -08:00
parent 0f204ae725
commit 4d70ba0802
2 changed files with 11 additions and 80 deletions

View File

@@ -254,8 +254,6 @@ void KeyActionUnicode(uint16_t unicode, int up, Display *display)
mapping = kvm_keyboard_map_unicode_key(display, unicode, &exists); mapping = kvm_keyboard_map_unicode_key(display, unicode, &exists);
if (mapping == 0) if (mapping == 0)
{ {
ILIBLOGMESSAGEX("UNICODE: %u => DOES NOT EXIST", unicode);
if (g_keyboardMap[g_keyboardMapIndex] != 0) if (g_keyboardMap[g_keyboardMapIndex] != 0)
{ {
mapping = g_keyboardMap[g_keyboardMapIndex] = kvm_keyboard_update_map_unicode_key(display, unicode, g_keyboardMap[g_keyboardMapIndex]); // Create a key mapping on an unmapped key mapping = g_keyboardMap[g_keyboardMapIndex] = kvm_keyboard_update_map_unicode_key(display, unicode, g_keyboardMap[g_keyboardMapIndex]); // Create a key mapping on an unmapped key
@@ -267,7 +265,6 @@ void KeyActionUnicode(uint16_t unicode, int up, Display *display)
} }
if (mapping > 0) if (mapping > 0)
{ {
ILIBLOGMESSAGEX("<<%d, EXISTS: %d>>", mapping, exists);
x11tst_exports->XTestFakeKeyEvent(display, mapping, 1, 0); x11tst_exports->XTestFakeKeyEvent(display, mapping, 1, 0);
x11tst_exports->XTestFakeKeyEvent(display, mapping, 0, 15); x11tst_exports->XTestFakeKeyEvent(display, mapping, 0, 15);
x11tst_exports->XFlush(display); x11tst_exports->XFlush(display);

View File

@@ -43,8 +43,6 @@ limitations under the License.
extern uint32_t crc32c(uint32_t crc, const unsigned char* buf, uint32_t len); extern uint32_t crc32c(uint32_t crc, const unsigned char* buf, uint32_t len);
extern char* g_ILibCrashDump_path; extern char* g_ILibCrashDump_path;
ILibQueue keyqueue = NULL;
typedef struct kvm_keydata typedef struct kvm_keydata
{ {
int delay; int delay;
@@ -108,8 +106,6 @@ extern int gRemoteMouseRenderDefault;
int remoteMouseX = 0, remoteMouseY = 0; int remoteMouseX = 0, remoteMouseY = 0;
ILibQueue g_messageQ;
extern void* tilebuffer; extern void* tilebuffer;
extern char **environ; extern char **environ;
struct timespec inputtime; struct timespec inputtime;
@@ -197,7 +193,7 @@ int kvm_keyboard_map_unicode_key(Display *display, uint16_t unicode, int *alread
// Convert the unicode character to something xorg will understand // Convert the unicode character to something xorg will understand
if (sprintf_s(unicodestring, sizeof(unicodestring), "U%04X", unicode) < 0) { return(-1); } if (sprintf_s(unicodestring, sizeof(unicodestring), "U%04X", unicode) < 0) { return(-1); }
KeySym sym = x11_exports->XStringToKeysym(unicodestring); KeySym sym = x11_exports->XStringToKeysym(unicodestring);
ILIBLOGMESSAGEX("UNICODE SYM: %X", sym); //ILIBLOGMESSAGEX("UNICODE SYM: %X", sym);
// Get the keycode range that is supported on this platform // Get the keycode range that is supported on this platform
x11_exports->XDisplayKeycodes(display, &keycode_low, &keycode_high); x11_exports->XDisplayKeycodes(display, &keycode_low, &keycode_high);
@@ -213,14 +209,14 @@ int kvm_keyboard_map_unicode_key(Display *display, uint16_t unicode, int *alread
if (keysyms[keycodeIndex] == sym) if (keysyms[keycodeIndex] == sym)
{ {
// We have a match! // We have a match!
ILIBLOGMESSAGEX(" Already mapped at: %d", foundCode); //ILIBLOGMESSAGEX(" Already mapped at: %d", foundCode);
empty_keycode = foundCode; empty_keycode = foundCode;
*alreadyExists = 1; *alreadyExists = 1;
} }
else else
{ {
// No match! // No match!
ILIBLOGMESSAGEX(" Already mapped at: %d, but is not PRIMARY", foundCode); //ILIBLOGMESSAGEX(" Already mapped at: %d, but is not PRIMARY", foundCode);
} }
} }
} }
@@ -256,15 +252,12 @@ int kvm_keyboard_map_unicode_key(Display *display, uint16_t unicode, int *alread
void kvm_send_error(char *msg) void kvm_send_error(char *msg)
{ {
int msgLen = strnlen_s(msg, 255); int msgLen = strnlen_s(msg, 255);
char *buffer = (char*)ILibMemory_SmartAllocate(msgLen + 4); char buffer[512];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_ERROR); // Write the type ((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_ERROR); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)(msgLen + 4)); // Write the size ((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)(msgLen + 4)); // Write the size
memcpy_s(buffer + 4, msgLen, msg, msgLen); memcpy_s(buffer + 4, msgLen, msg, msgLen);
ignore_result(write(slave2master[1], buffer, msgLen + 2));
ILibQueue_Lock(g_messageQ);
ILibQueue_EnQueue(g_messageQ, buffer);
ILibQueue_UnLock(g_messageQ);
} }
KVM_MouseCursors kvm_fetch_currentCursor(Display *cursordisplay) KVM_MouseCursors kvm_fetch_currentCursor(Display *cursordisplay)
@@ -397,29 +390,23 @@ KVM_MouseCursors kvm_fetch_currentCursor(Display *cursordisplay)
} }
void kvm_send_resolution() void kvm_send_resolution()
{ {
char *buffer = (char*)ILibMemory_SmartAllocate(8); char buffer[8];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SCREEN); // Write the type ((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SCREEN); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)8); // Write the size ((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)8); // Write the size
((unsigned short*)buffer)[2] = (unsigned short)htons((unsigned short)SCREEN_WIDTH); // X position ((unsigned short*)buffer)[2] = (unsigned short)htons((unsigned short)SCREEN_WIDTH); // X position
((unsigned short*)buffer)[3] = (unsigned short)htons((unsigned short)SCREEN_HEIGHT); // Y position ((unsigned short*)buffer)[3] = (unsigned short)htons((unsigned short)SCREEN_HEIGHT); // Y position
ILibQueue_Lock(g_messageQ); ignore_result(write(slave2master[1], buffer, sizeof(buffer)));
ILibQueue_EnQueue(g_messageQ, buffer);
ILibQueue_UnLock(g_messageQ);
} }
void kvm_send_display() void kvm_send_display()
{ {
char* buffer = (char*)ILibMemory_SmartAllocate(5); char buffer[5];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SET_DISPLAY); // Write the type ((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SET_DISPLAY); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)5); // Write the size ((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)5); // Write the size
buffer[4] = current_display; // Display number buffer[4] = current_display; // Display number
ILibQueue_Lock(g_messageQ); ignore_result(write(slave2master[1], buffer, sizeof(buffer)));
ILibQueue_EnQueue(g_messageQ, buffer);
ILibQueue_UnLock(g_messageQ);
} }
#define BUFSIZE 65535 #define BUFSIZE 65535
@@ -518,9 +505,7 @@ void kvm_send_display_list()
} }
((unsigned short*)buffer)[i + 3] = (unsigned short)htons((unsigned short)current_display); // Current display ((unsigned short*)buffer)[i + 3] = (unsigned short)htons((unsigned short)current_display); // Current display
ILibQueue_Lock(g_messageQ); ignore_result(write(slave2master[1], buffer, ILibMemory_Size(buffer)));
ILibQueue_EnQueue(g_messageQ, buffer);
ILibQueue_UnLock(g_messageQ);
} }
char Location_X11LIB[NAME_MAX]; char Location_X11LIB[NAME_MAX];
@@ -822,9 +807,7 @@ void kvm_server_jpegerror(char *msg)
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)(msgLen + 4)); // Write the size ((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)(msgLen + 4)); // Write the size
memcpy_s(buffer + 4, msgLen, msg, msgLen); memcpy_s(buffer + 4, msgLen, msg, msgLen);
ILibQueue_Lock(g_messageQ); ignore_result(write(slave2master[1], buffer, ILibMemory_Size(buffer)));
ILibQueue_EnQueue(g_messageQ, buffer);
ILibQueue_UnLock(g_messageQ);
} }
#pragma pack(push, 1) #pragma pack(push, 1)
@@ -1007,7 +990,6 @@ void* kvm_server_mainloop(void* parm)
} }
} }
} }
g_messageQ = ILibQueue_Create();
// Init the kvm // Init the kvm
//fprintf(logFile, "Before kvm_init.\n"); fflush(logFile); //fprintf(logFile, "Before kvm_init.\n"); fflush(logFile);
@@ -1032,24 +1014,10 @@ void* kvm_server_mainloop(void* parm)
int len = 0; int len = 0;
char pchRequest2[30000]; char pchRequest2[30000];
ssize_t cbBytesRead = 0; ssize_t cbBytesRead = 0;
keyqueue = ILibCircularQueue_Create(sizeof(kvm_keydata), 1024);
kvm_keydata *keydata; kvm_keydata *keydata;
while (!g_shutdown) while (!g_shutdown)
{ {
// Check if there are pending messages to be sent
ILibQueue_Lock(g_messageQ);
while (ILibQueue_IsEmpty(g_messageQ) == 0)
{
if ((buf = (char*)ILibQueue_DeQueue(g_messageQ)) != NULL)
{
written = write(slave2master[1], buf, ILibMemory_Size(buf));
fsync(slave2master[1]);
ILibMemory_Free(buf);
}
}
ILibQueue_UnLock(g_messageQ);
for (r = 0; r < TILE_HEIGHT_COUNT; r++) for (r = 0; r < TILE_HEIGHT_COUNT; r++)
{ {
for (c = 0; c < TILE_WIDTH_COUNT; c++) for (c = 0; c < TILE_WIDTH_COUNT; c++)
@@ -1344,43 +1312,10 @@ void* kvm_server_mainloop(void* parm)
height = 0; height = 0;
} }
while ((keydata = (kvm_keydata*)ILibCircularQueue_Peek(keyqueue)) != NULL)
{
if (keydata->delay > 0)
{
// Need to sleep, calculate how much
if (keydata->delay > maxsleep)
{
// Frame Rate Timer is smaller
keydata->delay -= maxsleep;
break;
}
else
{
// Frame Rate timer is larger
maxsleep -= keydata->delay;
usleep(keydata->delay);
keydata->delay = 0;
continue;
}
}
keydata = (kvm_keydata*)ILibCircularQueue_DeQueue(keyqueue);
if (keydata->delay == 0)
{
KeyActionUnicode(keydata->data, keydata->up, eventdisplay);
}
else
{
KeyAction((unsigned char)keydata->data, keydata->up, eventdisplay);
}
}
usleep(maxsleep); usleep(maxsleep);
} }
} }
ILibCircularQueue_Destroy(keyqueue);
close(slave2master[1]); close(slave2master[1]);
close(master2slave[0]); close(master2slave[0]);
slave2master[1] = 0; slave2master[1] = 0;
@@ -1403,7 +1338,6 @@ void* kvm_server_mainloop(void* parm)
g_tileInfo = NULL; g_tileInfo = NULL;
} }
if(tilebuffer != NULL) { free(tilebuffer); tilebuffer = NULL; } if(tilebuffer != NULL) { free(tilebuffer); tilebuffer = NULL; }
ILibQueue_Destroy(g_messageQ);
return (void*)0; return (void*)0;
} }