Move definitions from header to CPP
This commit is contained in:
parent
9b30c28fa6
commit
0d942f9286
|
|
@ -16,8 +16,51 @@
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void cleanup_pipe()
|
||||||
|
{
|
||||||
|
unlink(PIPE_PATH);
|
||||||
|
remove(PIPE_PATH);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int server_thread(void *data)
|
||||||
|
{
|
||||||
|
(void)data;
|
||||||
|
#if defined OS_W32
|
||||||
|
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
||||||
|
PIPE_ACCESS_OUTBOUND,
|
||||||
|
PIPE_TYPE_BYTE | PIPE_WAIT,
|
||||||
|
PIPE_UNLIMITED_INSTANCES,
|
||||||
|
BUFFER_SIZE,
|
||||||
|
BUFFER_SIZE,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
for (;;) {
|
||||||
|
ConnectNamedPipe(pipe, NULL);
|
||||||
|
SDL_LockMutex(mutex);
|
||||||
|
DWORD written;
|
||||||
|
WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL);
|
||||||
|
active = true;
|
||||||
|
SDL_UnlockMutex(mutex);
|
||||||
|
FlushFileBuffers(pipe);
|
||||||
|
DisconnectNamedPipe(pipe);
|
||||||
|
}
|
||||||
|
CloseHandle(pipe);
|
||||||
|
#else
|
||||||
|
if (FILE *file = fopen(PIPE_PATH, "r")) {
|
||||||
|
fclose(file);
|
||||||
|
out_pipe = open(PIPE_PATH, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
SDL_LockMutex(mutex);
|
||||||
|
active = true;
|
||||||
|
if (message_len > 0)
|
||||||
|
write(out_pipe, (char*)message_buffer, message_len);
|
||||||
|
SDL_UnlockMutex(mutex);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
RB_METHOD(journalSet)
|
RB_METHOD(journalSet)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
|
||||||
|
|
@ -43,46 +43,7 @@ static volatile int message_len = 0;
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
#define PIPE_PATH "/tmp/oneshot-pipe"
|
#define PIPE_PATH "/tmp/oneshot-pipe"
|
||||||
static volatile int out_pipe = -1;
|
static volatile int out_pipe = -1;
|
||||||
void cleanup_pipe()
|
void cleanup_pipe();
|
||||||
{
|
|
||||||
unlink(PIPE_PATH);
|
|
||||||
remove(PIPE_PATH);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int server_thread(void *data)
|
int server_thread(void *data);
|
||||||
{
|
|
||||||
(void)data;
|
|
||||||
#if defined OS_W32
|
|
||||||
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
|
||||||
PIPE_ACCESS_OUTBOUND,
|
|
||||||
PIPE_TYPE_BYTE | PIPE_WAIT,
|
|
||||||
PIPE_UNLIMITED_INSTANCES,
|
|
||||||
BUFFER_SIZE,
|
|
||||||
BUFFER_SIZE,
|
|
||||||
0,
|
|
||||||
NULL);
|
|
||||||
for (;;) {
|
|
||||||
ConnectNamedPipe(pipe, NULL);
|
|
||||||
SDL_LockMutex(mutex);
|
|
||||||
DWORD written;
|
|
||||||
WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL);
|
|
||||||
active = true;
|
|
||||||
SDL_UnlockMutex(mutex);
|
|
||||||
FlushFileBuffers(pipe);
|
|
||||||
DisconnectNamedPipe(pipe);
|
|
||||||
}
|
|
||||||
CloseHandle(pipe);
|
|
||||||
#else
|
|
||||||
if (FILE *file = fopen(PIPE_PATH, "r")) {
|
|
||||||
fclose(file);
|
|
||||||
out_pipe = open(PIPE_PATH, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
|
||||||
SDL_LockMutex(mutex);
|
|
||||||
active = true;
|
|
||||||
if (message_len > 0)
|
|
||||||
write(out_pipe, (char*)message_buffer, message_len);
|
|
||||||
SDL_UnlockMutex(mutex);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue