mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[client] added ivshmem_process thread and fixed shutdown behaviour
This commit is contained in:
parent
327a3a77cf
commit
3a7bff77f2
@ -42,6 +42,7 @@ struct IVSHMEMClient
|
|||||||
struct IVSHMEM
|
struct IVSHMEM
|
||||||
{
|
{
|
||||||
bool connected;
|
bool connected;
|
||||||
|
bool shutdown;
|
||||||
int socket;
|
int socket;
|
||||||
struct IVSHMEMServer server;
|
struct IVSHMEMServer server;
|
||||||
struct IVSHMEMClient * clients;
|
struct IVSHMEMClient * clients;
|
||||||
@ -53,6 +54,7 @@ struct IVSHMEM
|
|||||||
struct IVSHMEM ivshmem =
|
struct IVSHMEM ivshmem =
|
||||||
{
|
{
|
||||||
.connected = false,
|
.connected = false,
|
||||||
|
.shutdown = false,
|
||||||
.socket = -1
|
.socket = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,6 +71,7 @@ void ivshmem_remove_client(struct IVSHMEMClient * client);
|
|||||||
|
|
||||||
bool ivshmem_connect(const char * unix_socket)
|
bool ivshmem_connect(const char * unix_socket)
|
||||||
{
|
{
|
||||||
|
ivshmem.shutdown = false;
|
||||||
ivshmem.socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
ivshmem.socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (ivshmem.socket < 0)
|
if (ivshmem.socket < 0)
|
||||||
{
|
{
|
||||||
@ -177,6 +180,8 @@ void ivshmem_cleanup()
|
|||||||
|
|
||||||
if (ivshmem.socket >= 0)
|
if (ivshmem.socket >= 0)
|
||||||
{
|
{
|
||||||
|
ivshmem.shutdown = true;
|
||||||
|
shutdown(ivshmem.socket, SHUT_RDWR);
|
||||||
close(ivshmem.socket);
|
close(ivshmem.socket);
|
||||||
ivshmem.socket = -1;
|
ivshmem.socket = -1;
|
||||||
}
|
}
|
||||||
@ -186,7 +191,7 @@ void ivshmem_cleanup()
|
|||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void ivshmem_close()
|
void ivshmem_disconnect()
|
||||||
{
|
{
|
||||||
if (!ivshmem.connected)
|
if (!ivshmem.connected)
|
||||||
{
|
{
|
||||||
@ -250,13 +255,15 @@ bool ivshmem_read_msg(int64_t * index, int * fd)
|
|||||||
int ret = recvmsg(ivshmem.socket, &msg, 0);
|
int ret = recvmsg(ivshmem.socket, &msg, 0);
|
||||||
if (ret < sizeof(*index))
|
if (ret < sizeof(*index))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("failed ot read message\n");
|
if (!ivshmem.shutdown)
|
||||||
|
DEBUG_ERROR("failed to read message\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lost connetion to server\n");
|
if (!ivshmem.shutdown)
|
||||||
|
DEBUG_ERROR("lost connetion to server\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +286,17 @@ bool ivshmem_read_msg(int64_t * index, int * fd)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t ivshmem_get_id()
|
||||||
|
{
|
||||||
|
if (!ivshmem.connected)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("not connected");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ivshmem.server.clientID;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void * ivshmem_get_map()
|
void * ivshmem_get_map()
|
||||||
@ -378,7 +396,8 @@ bool ivshmem_process()
|
|||||||
|
|
||||||
if (!ivshmem_read_msg(&index, &fd))
|
if (!ivshmem_read_msg(&index, &fd))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("failed to read message");
|
if (!ivshmem.shutdown)
|
||||||
|
DEBUG_ERROR("failed to read message");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
bool ivshmem_connect(const char * unix_socket);
|
bool ivshmem_connect(const char * unix_socket);
|
||||||
void ivshmem_close();
|
void ivshmem_disconnect();
|
||||||
bool ivshmem_process();
|
bool ivshmem_process();
|
||||||
|
|
||||||
void * ivshmem_get_map();
|
uint16_t ivshmem_get_id();
|
||||||
size_t ivshmem_get_map_size();
|
void * ivshmem_get_map();
|
||||||
|
size_t ivshmem_get_map_size();
|
@ -327,13 +327,32 @@ int renderThread(void * unused)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ivshmemThread(void * arg)
|
||||||
|
{
|
||||||
|
while(state.running)
|
||||||
|
if (!ivshmem_process())
|
||||||
|
{
|
||||||
|
if (state.running)
|
||||||
|
{
|
||||||
|
state.running = false;
|
||||||
|
DEBUG_ERROR("failed to process ivshmem messages");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int spiceThread(void * arg)
|
int spiceThread(void * arg)
|
||||||
{
|
{
|
||||||
while(state.running)
|
while(state.running)
|
||||||
if (!spice_process())
|
if (!spice_process())
|
||||||
{
|
{
|
||||||
state.running = false;
|
if (state.running)
|
||||||
DEBUG_ERROR("Failed to process spice messages");
|
{
|
||||||
|
state.running = false;
|
||||||
|
DEBUG_ERROR("failed to process spice messages");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,9 +482,10 @@ int main(int argc, char * argv[])
|
|||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
state.running = true;
|
state.running = true;
|
||||||
|
|
||||||
int shm_fd = 0;
|
int shm_fd = 0;
|
||||||
SDL_Thread *t_spice = NULL;
|
SDL_Thread *t_ivshmem = NULL;
|
||||||
SDL_Thread *t_event = NULL;
|
SDL_Thread *t_spice = NULL;
|
||||||
|
SDL_Thread *t_event = NULL;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
@ -475,6 +495,12 @@ int main(int argc, char * argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(t_ivshmem = SDL_CreateThread(ivshmemThread, "ivshmemThread", NULL)))
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("ivshmem create thread failed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
state.shm = (struct KVMGFXHeader *)ivshmem_get_map();
|
state.shm = (struct KVMGFXHeader *)ivshmem_get_map();
|
||||||
if (!state.shm)
|
if (!state.shm)
|
||||||
{
|
{
|
||||||
@ -519,6 +545,12 @@ int main(int argc, char * argv[])
|
|||||||
if (t_event)
|
if (t_event)
|
||||||
SDL_WaitThread(t_event, NULL);
|
SDL_WaitThread(t_event, NULL);
|
||||||
|
|
||||||
|
// this needs to happen here to abort any waiting reads
|
||||||
|
// as ivshmem uses recvmsg which has no timeout
|
||||||
|
ivshmem_disconnect();
|
||||||
|
if (t_ivshmem)
|
||||||
|
SDL_WaitThread(t_ivshmem, NULL);
|
||||||
|
|
||||||
if (t_spice)
|
if (t_spice)
|
||||||
SDL_WaitThread(t_spice, NULL);
|
SDL_WaitThread(t_spice, NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user