Move definitions from header to CPP

This commit is contained in:
Vinyl Darkscratch 2018-05-02 19:29:45 -07:00
parent 9b30c28fa6
commit 0d942f9286
2 changed files with 45 additions and 41 deletions

View file

@ -16,8 +16,51 @@
#endif
#include <unistd.h>
#include <stdio.h>
void cleanup_pipe()
{
unlink(PIPE_PATH);
remove(PIPE_PATH);
}
#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_UNUSED_PARAM;

View file

@ -43,46 +43,7 @@ static volatile int message_len = 0;
#ifdef LINUX
#define PIPE_PATH "/tmp/oneshot-pipe"
static volatile int out_pipe = -1;
void cleanup_pipe()
{
unlink(PIPE_PATH);
remove(PIPE_PATH);
}
void cleanup_pipe();
#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
}
int server_thread(void *data);