Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame^] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include <stdexcept> |
| 7 | #include "TcpTransport.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | void 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 | |
| 20 | void 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 | |
| 27 | unsigned 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 | } |