aboutsummaryrefslogtreecommitdiff
path: root/bikewedge/software/RetoolingForOpenSprints/serproxy-0.1.3.src/pipe.c
blob: 48a82f32138bbd4cd83d349245e4bc76954f0efe (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
39
40
41
42
43
/*
 * pipe.c
 *
 * serial port <-> TCP/IP piping
 *
 * (C)1999 Stefano Busti
 *
 */

#include <stdlib.h>

#include "pipe.h"

int pipe_init(pipe_s *pipe, int sock_port)
{
	if (sio_init(&pipe->sio))
		return -1;

	if (tcp_init(&pipe->sock, sock_port))
		return -1;

	pipe->mutex = malloc(sizeof(thr_mutex_t));
	*(pipe->mutex) = thr_mutex_create();
	
	return 0;
}

void pipe_cleanup(pipe_s *pipe)
{
	sio_cleanup(&pipe->sio);
	tcp_cleanup(&pipe->sock);
	thr_mutex_unlock(pipe->mutex);
	thr_mutex_destroy(pipe->mutex);
	free(pipe->mutex);
}

void pipe_destroy(void *data)
{
	pipe_s *pipe = (pipe_s *)data;

	pipe_cleanup(pipe);
	free(pipe);
}