blob: 7a3a190163d95870b4f6c66b4b37933b4e3fa361 [file] [log] [blame]
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include <stdexcept>
7#include "TcpTransport.hpp"
8
9using namespace std;
10
11namespace ndn {
12
13void TcpTransport::connect(char *host, unsigned short port)
14{
15 ndn_Error error;
16 if (error = ndn_TcpTransport_connect(&transport_, host, port))
17 throw std::runtime_error(ndn_getErrorString(error));
18}
19
20void TcpTransport::send(unsigned char *data, unsigned int dataLength)
21{
22 ndn_Error error;
23 if (error = ndn_TcpTransport_send(&transport_, data, dataLength))
24 throw std::runtime_error(ndn_getErrorString(error));
25}
26
27unsigned int TcpTransport::receive(unsigned char *buffer, unsigned int bufferLength)
28{
29 ndn_Error error;
30 unsigned int nBytes;
31 if (error = ndn_TcpTransport_receive(&transport_, buffer, bufferLength, &nBytes))
32 throw std::runtime_error(ndn_getErrorString(error));
33
34 return nBytes;
35}
36
37}