summaryrefslogtreecommitdiffhomepage
path: root/connection.c
blob: b0d9fcc190fd8fe78aa8b0ecf9ecf56a8a63ca85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "connection.h"

#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <lauxlib.h>
#include <lua.h>

/// Creates new connection.
/// \param client File descriptor of client's socket
/// \return Pointer to connection or NULL if an error occured
struct connection * connection_new(const int client)
{
	struct connection * c = malloc(sizeof(struct connection));

	if (NULL == c)
	{
		return NULL;
	}

	memset(c, 0, sizeof(struct connection));

	c->fd = client;
	c->ref = LUA_NOREF;
	c->L = NULL;
	c->push = 0;

	return c;
}

/// Frees all resources associated with the connection.
/// \param c Connection to free
void connection_free(struct connection * c)
{
	close(c->fd); // TODO: Check for errors in close()?
	free(c);
}