blob: 9167beb35463de7932de32bde54e77c0a4ce46de [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#ifndef NDN_TCPTRANSPORT_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_TCPTRANSPORT_HPP
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "../c/transport/tcp-transport.h"
10#include "../c/encoding/binary-xml-element-reader.h"
11#include "transport.hpp"
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070012
13namespace ndn {
14
15class TcpTransport : public Transport {
16public:
17 TcpTransport()
18 {
19 ndn_TcpTransport_init(&transport_);
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070020 face_ = 0;
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070021 }
22
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070023 /**
Jeff Thompson432c8be2013-08-09 16:16:08 -070024 * Connect to the host specified in face.
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070025 * @param face Not a shared_ptr because we assume that it will remain valid during the life of this Transport object.
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070026 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070027 virtual void connect(Face &face);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070028
Jeff Thompson432c8be2013-08-09 16:16:08 -070029 /**
30 * Set data to the host
31 * @param data A pointer to the buffer of data to send.
32 * @param dataLength The number of bytes in data.
33 */
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070034 virtual void send(const unsigned char *data, unsigned int dataLength);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070035
Jeff Thompson432c8be2013-08-09 16:16:08 -070036 /**
37 * Process any data to receive. For each element received, call face.onReceivedElement.
38 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
39 * You should repeatedly call this from an event loop.
40 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
41 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
42 */
43 virtual void processEvents();
Jeff Thompson57963882013-08-05 16:01:25 -070044
Jeff Thompson432c8be2013-08-09 16:16:08 -070045 /**
46 * Close the connection to the host.
47 */
Jeff Thompson57963882013-08-05 16:01:25 -070048 virtual void close();
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070049
50private:
51 struct ndn_TcpTransport transport_;
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070052 Face *face_;
Jeff Thompsonb002f902013-07-16 18:07:18 -070053 // TODO: This belongs in the socket listener.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070054 ndn_BinaryXmlElementReader elementReader_;
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070055};
56
57}
58
59#endif