i forgor that common lib is technically a system lib so it should be in <> and not ""
This commit is contained in:
parent
4655a9d9b9
commit
bfbba84b5c
@ -4,8 +4,9 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "world.h"
|
||||
#include "error.h"
|
||||
#include <world.h>
|
||||
#include <error.h>
|
||||
|
||||
#include "sock.h"
|
||||
|
||||
int main(void) {
|
||||
@ -13,31 +14,31 @@ int main(void) {
|
||||
|
||||
int sock;
|
||||
err = sock_init(&sock);
|
||||
if (err) goto handle_error;
|
||||
if (err) goto error;
|
||||
|
||||
char ibuf[8192] = { 0 };
|
||||
read(sock, ibuf, 8192);
|
||||
|
||||
struct world_t world = { 0 };
|
||||
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(" (%zu %zu)\n", world.height, world.width);
|
||||
|
||||
char obuf[8192] = { 0 };
|
||||
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);
|
||||
|
||||
close(sock);
|
||||
return ERR_OK;
|
||||
|
||||
handle_error_sock:
|
||||
error_socket:
|
||||
close(sock);
|
||||
|
||||
handle_error:
|
||||
error:
|
||||
printf("CLIENT ERROR: %s\n", ERROR_STRS[err]);
|
||||
return err;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef RENDER_H
|
||||
#define RENDER_H
|
||||
|
||||
#include "world.h"
|
||||
#include <world.h>
|
||||
|
||||
void render_world(struct world_t const *);
|
||||
|
||||
|
@ -12,19 +12,20 @@ enum error_t sock_init(int *sockptr) {
|
||||
assert(sockptr != NULL);
|
||||
|
||||
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 };
|
||||
sa.sun_family = AF_UNIX;
|
||||
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;
|
||||
return ERR_OK;
|
||||
|
||||
sock_error:
|
||||
error_connect:
|
||||
close(sock);
|
||||
sock_init_error:
|
||||
|
||||
error:
|
||||
return ERR_SOCKET;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef SOCK_H
|
||||
#define SOCK_H
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
#define SOCK_PATH "/tmp/swd.sock"
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
A list of things I'd like to accomplish
|
||||
|
||||
## 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)
|
||||
|
||||
## Completed
|
||||
@ -16,7 +19,7 @@ A list of things I'd like to accomplish
|
||||
* Write Makefile to automate compilation
|
||||
|
||||
## Planned
|
||||
* Game loop
|
||||
* Split game ticking and socket connecting logic (can only tick on connection atm)
|
||||
* Create and load worlds
|
||||
* Display environment and pan camera
|
||||
* Time controls (play/pause/speed up)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef DAEMON_H
|
||||
#define DAEMON_H
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
enum error_t daemonise(void);
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#ifndef DAEMON_DATA_H
|
||||
#define DAEMON_DATA_H
|
||||
|
||||
#include "world.h"
|
||||
#include <world.h>
|
||||
|
||||
#include "opts.h"
|
||||
|
||||
struct data_t {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
#include "opts.h"
|
||||
#include "sock.h"
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
struct options_t {
|
||||
bool daemonise;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef SOCK_H
|
||||
#define SOCK_H
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user