blob: 0011e2670ef8472a7b57cf662d62aafd7e85bad9 [file] [log] [blame]
Jeff Thompson0aa754a2013-07-17 17:42:28 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_SOCKETTRANSPORT_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_SOCKETTRANSPORT_H
Jeff Thompson0aa754a2013-07-17 17:42:28 -07008
9#include <sys/socket.h>
10#include "../errors.h"
11
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompson0aa754a2013-07-17 17:42:28 -070013extern "C" {
14#endif
15
16typedef enum {
17 SOCKET_TCP,
18 SOCKET_UDP
19} ndn_SocketType;
20
21struct ndn_SocketTransport {
22 int socketDescriptor; /**< -1 if not connected */
23};
24
25static inline void ndn_SocketTransport_init(struct ndn_SocketTransport *self)
26{
27 self->socketDescriptor = -1;
28}
29
30ndn_Error ndn_SocketTransport_connect(struct ndn_SocketTransport *self, ndn_SocketType socketType, char *host, unsigned short port);
31
32ndn_Error ndn_SocketTransport_send(struct ndn_SocketTransport *self, unsigned char *data, unsigned int dataLength);
33
34ndn_Error ndn_SocketTransport_receive
35 (struct ndn_SocketTransport *self, unsigned char *buffer, unsigned int bufferLength, unsigned int *nBytes);
36
Jeff Thompson57963882013-08-05 16:01:25 -070037ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self);
38
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070039#ifdef __cplusplus
Jeff Thompson0aa754a2013-07-17 17:42:28 -070040}
41#endif
42
43#endif