diff options
-rw-r--r-- | server.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/server.c b/server.c index 314fccd..b57b86a 100644 --- a/server.c +++ b/server.c @@ -67,7 +67,7 @@ static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) { return tile; } -static const struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) { +static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) { struct Tile *tile = tileGet(tileX, tileY); tile->accessTime = time(NULL); tile->accessCount++; @@ -81,6 +81,12 @@ static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) { return tile; } +static struct Tile *tileSync(struct Tile *tile) { + int error = msync(tile, sizeof(*tile), MS_ASYNC); + if (error) err(EX_IOERR, "msync"); + return tile; +} + enum { ClientsCap = 256 }; static struct Client { int fd; @@ -107,7 +113,9 @@ clientSend(const struct Client *client, const struct ServerMessage *msg) { ssize_t len = send(client->fd, msg, sizeof(*msg), 0); if (len < 0) return -1; if (msg->type == ServerTile) { - const struct Tile *tile = tileAccess(client->tileX, client->tileY); + const struct Tile *tile = tileSync( + tileAccess(client->tileX, client->tileY) + ); len = send(client->fd, tile, sizeof(*tile), 0); if (len < 0) return -1; } @@ -251,6 +259,7 @@ static int clientPut(const struct Client *client, uint8_t color, uint8_t cell) { struct Tile *tile = tileModify(client->tileX, client->tileY); tile->colors[client->cellY][client->cellX] = color; tile->cells[client->cellY][client->cellX] = cell; + tileSync(tile); struct ServerMessage msg = { .type = ServerPut, .put = { |