aboutsummaryrefslogtreecommitdiff
path: root/iemnet.h
blob: 390e1ea3b8d60aa97a7f0708eedf613699a28c58 (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
#include "m_pd.h"

#include <sys/socket.h>

typedef struct _iemnet_chunk {
  unsigned char* data;
  size_t size;
} t_iemnet_chunk;

void iemnet__chunk_destroy(t_iemnet_chunk*);
t_iemnet_chunk*iemnet__chunk_create_empty(int);
t_iemnet_chunk*iemnet__chunk_create_data(int, unsigned char*);
t_iemnet_chunk*iemnet__chunk_create_list(int, t_atom*);
t_iemnet_chunk*iemnet__chunk_create_chunk(t_iemnet_chunk*);

t_atom*iemnet__chunk2list(t_iemnet_chunk*);

/* sender */
#define t_iemnet_sender struct _iemnet_sender
EXTERN_STRUCT _iemnet_sender;

t_iemnet_sender*iemnet__sender_create(int sock);
void iemnet__sender_destroy(t_iemnet_sender*);

int iemnet__sender_send(t_iemnet_sender*, t_iemnet_chunk*);

int iemnet__sender_getlasterror(t_iemnet_sender*);
int iemnet__sender_getsockopt(t_iemnet_sender*, int level, int optname, void      *optval, socklen_t*optlen);
int iemnet__sender_setsockopt(t_iemnet_sender*, int level, int optname, const void*optval, socklen_t optlen);


/* receiver */
#define t_iemnet_receiver struct _iemnet_receiver
EXTERN_STRUCT _iemnet_receiver;

typedef void (*t_iemnet_receivecallback)(void*x, int, t_iemnet_chunk*);

/**
 * create a receiver object: whenever something is received on the socket,
 * the callback is called with the payload
 */
t_iemnet_receiver*iemnet__receiver_create(int sock, void*owner, t_iemnet_receivecallback callback);
void iemnet__receiver_destroy(t_iemnet_receiver*);