i forgor that common lib is technically a system lib so it should be in <> and not ""

This commit is contained in:
snit 2024-10-17 15:14:16 -05:00
parent 4655a9d9b9
commit bfbba84b5c
10 changed files with 25 additions and 19 deletions

View File

@ -4,8 +4,9 @@
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "world.h" #include <world.h>
#include "error.h" #include <error.h>
#include "sock.h" #include "sock.h"
int main(void) { int main(void) {
@ -13,31 +14,31 @@ int main(void) {
int sock; int sock;
err = sock_init(&sock); err = sock_init(&sock);
if (err) goto handle_error; if (err) goto error;
char ibuf[8192] = { 0 }; char ibuf[8192] = { 0 };
read(sock, ibuf, 8192); read(sock, ibuf, 8192);
struct world_t world = { 0 }; struct world_t world = { 0 };
err = world_deserialise_str(&world, ibuf); err = world_deserialise_str(&world, ibuf);
if (err != ERR_OK) goto handle_error_sock; if (err != ERR_OK) goto error_socket;
printf("CLIENT: (%zu %zu) ->", world.height++, world.width ++); printf("CLIENT: (%zu %zu) ->", world.height++, world.width ++);
printf(" (%zu %zu)\n", world.height, world.width); printf(" (%zu %zu)\n", world.height, world.width);
char obuf[8192] = { 0 }; char obuf[8192] = { 0 };
err = world_serialise_buf(&world, obuf, 8192); err = world_serialise_buf(&world, obuf, 8192);
if (err != ERR_OK) goto handle_error_sock; if (err != ERR_OK) goto error_socket;
write(sock, obuf, 8192); write(sock, obuf, 8192);
close(sock); close(sock);
return ERR_OK; return ERR_OK;
handle_error_sock: error_socket:
close(sock); close(sock);
handle_error: error:
printf("CLIENT ERROR: %s\n", ERROR_STRS[err]); printf("CLIENT ERROR: %s\n", ERROR_STRS[err]);
return err; return err;
} }

View File

@ -1,7 +1,7 @@
#ifndef RENDER_H #ifndef RENDER_H
#define RENDER_H #define RENDER_H
#include "world.h" #include <world.h>
void render_world(struct world_t const *); void render_world(struct world_t const *);

View File

@ -12,19 +12,20 @@ enum error_t sock_init(int *sockptr) {
assert(sockptr != NULL); assert(sockptr != NULL);
int const sock = socket(AF_UNIX, SOCK_STREAM, 0); int const sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) goto sock_init_error; if (sock < 0) goto error;
struct sockaddr_un sa = { 0 }; struct sockaddr_un sa = { 0 };
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, SOCK_PATH); strcpy(sa.sun_path, SOCK_PATH);
if (connect(sock, (struct sockaddr *)&sa, sizeof(sa))) goto sock_error; if (connect(sock, (struct sockaddr *)&sa, sizeof(sa))) goto error_connect;
*sockptr = sock; *sockptr = sock;
return ERR_OK; return ERR_OK;
sock_error: error_connect:
close(sock); close(sock);
sock_init_error:
error:
return ERR_SOCKET; return ERR_SOCKET;
} }

View File

@ -1,7 +1,7 @@
#ifndef SOCK_H #ifndef SOCK_H
#define SOCK_H #define SOCK_H
#include "error.h" #include <error.h>
#define SOCK_PATH "/tmp/swd.sock" #define SOCK_PATH "/tmp/swd.sock"

View File

@ -2,6 +2,9 @@
A list of things I'd like to accomplish A list of things I'd like to accomplish
## In Progress ## In Progress
* Client send request
* Server handle request and send response
* Client handle response
* Have client render world data (return to pre-daemonised equivalent state) * Have client render world data (return to pre-daemonised equivalent state)
## Completed ## Completed
@ -16,7 +19,7 @@ A list of things I'd like to accomplish
* Write Makefile to automate compilation * Write Makefile to automate compilation
## Planned ## Planned
* Game loop * Split game ticking and socket connecting logic (can only tick on connection atm)
* Create and load worlds * Create and load worlds
* Display environment and pan camera * Display environment and pan camera
* Time controls (play/pause/speed up) * Time controls (play/pause/speed up)

View File

@ -1,7 +1,7 @@
#ifndef DAEMON_H #ifndef DAEMON_H
#define DAEMON_H #define DAEMON_H
#include "error.h" #include <error.h>
enum error_t daemonise(void); enum error_t daemonise(void);

View File

@ -1,7 +1,8 @@
#ifndef DAEMON_DATA_H #ifndef DAEMON_DATA_H
#define DAEMON_DATA_H #define DAEMON_DATA_H
#include "world.h" #include <world.h>
#include "opts.h" #include "opts.h"
struct data_t { struct data_t {

View File

@ -8,7 +8,7 @@
#include <sys/syslog.h> #include <sys/syslog.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "error.h" #include <error.h>
#include "opts.h" #include "opts.h"
#include "sock.h" #include "sock.h"

View File

@ -3,7 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "error.h" #include <error.h>
struct options_t { struct options_t {
bool daemonise; bool daemonise;

View File

@ -1,7 +1,7 @@
#ifndef SOCK_H #ifndef SOCK_H
#define SOCK_H #define SOCK_H
#include "error.h" #include <error.h>
#include "data.h" #include "data.h"