blob: c3abab65433b995f2355c331cc3c860fe43a17a7 [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
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070013void TcpTransport::connect(const char *host, unsigned short port)
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070014{
15 ndn_Error error;
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070016 if (error = ndn_TcpTransport_connect(&transport_, (char *)host, port))
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070017 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}