socket-transport.h
1 
21 #ifndef NDN_SOCKETTRANSPORT_H
22 #define NDN_SOCKETTRANSPORT_H
23 
24 #include <sys/socket.h>
25 #include <ndn-cpp/c/common.h>
26 #include <ndn-cpp/c/errors.h>
27 #include <ndn-cpp/c/transport/transport-types.h>
28 #include "../encoding/element-reader.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 typedef enum {
35  SOCKET_TCP,
36  SOCKET_UDP,
37  SOCKET_UNIX
38 } ndn_SocketType;
39 
51 static __inline void ndn_SocketTransport_initialize
52  (struct ndn_SocketTransport *self, struct ndn_DynamicUInt8Array *buffer)
53 {
54  self->socketDescriptor = -1;
55  ndn_ElementReader_initialize(&self->elementReader, 0, buffer);
56 }
57 
71 ndn_Error ndn_SocketTransport_connect
72  (struct ndn_SocketTransport *self, ndn_SocketType socketType, const char *host,
73  unsigned short port, struct ndn_ElementListener *elementListener);
74 
82 ndn_Error ndn_SocketTransport_send(struct ndn_SocketTransport *self, const uint8_t *data, size_t dataLength);
83 
91 ndn_Error ndn_SocketTransport_receiveIsReady(struct ndn_SocketTransport *self, int *receiveIsReady);
92 
102 ndn_Error ndn_SocketTransport_receive
103  (struct ndn_SocketTransport *self, uint8_t *buffer, size_t bufferLength, size_t *nBytes);
104 
120 ndn_Error
121 ndn_SocketTransport_processEvents
122  (struct ndn_SocketTransport *self, uint8_t *buffer, size_t bufferLength);
123 
129 ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif
Copyright (C) 2015 Regents of the University of California.
Definition: transport-types.h:30
An ndn_ElementListener struct holds a function pointer onReceivedElement.
Definition: element-reader-types.h:37
A struct ndn_DynamicUInt8Array holds a pointer to an allocated array, the length of the allocated arr...
Definition: dynamic-uint8-array-types.h:40