diff --git a/inc/tcpstream.hpp b/inc/tcpstream.hpp index 05f69c51e8d494a54bf0727489153fb52ee02b79..63ff1fcf0c6bde66baf88f8ee0554e244fc517eb 100644 --- a/inc/tcpstream.hpp +++ b/inc/tcpstream.hpp @@ -1,6 +1,8 @@ #ifndef _TCPSTREAM_HPP #define _TCPSTREAM_HPP +#include <string> + #include "sockaddr.hpp" /** @@ -119,6 +121,16 @@ public: */ void sendAll(const void *data, size_t len); + /** + * @brief Send the given string data over the tcp connection. The function + * send all chars of the given string. + * + * If the sending fails, an exception is thrown. + * + * @param str The string that will be sent. + */ + void sendAllString(const std::string &str); + /** * @brief Receive a maximum of len bytes of data from the tcp connection. It * is possible that less than len bytes are received. This call will block diff --git a/src/tcpstream.cpp b/src/tcpstream.cpp index b47051606cc61840218ef0d7c86850e4dce6cfd6..630c928dd1affdda475ec7e9f4f954a70375c3e7 100644 --- a/src/tcpstream.cpp +++ b/src/tcpstream.cpp @@ -113,6 +113,11 @@ void TcpStream::sendAll(const void *data, size_t len) } } +void TcpStream::sendAllString(const std::string &str) +{ + sendAll(str.c_str(), str.size()); +} + ssize_t TcpStream::read(void *data, size_t len) { if (sockfd == 0)