Skip to content
Snippets Groups Projects
Commit 00be314f authored by Daniel Müller's avatar Daniel Müller :speech_balloon:
Browse files

Add sendAllString function for TcpStream

- The sendAllString function sends the provided string bytes
parent 9b6c992b
No related branches found
No related tags found
No related merge requests found
#ifndef _TCPSTREAM_HPP #ifndef _TCPSTREAM_HPP
#define _TCPSTREAM_HPP #define _TCPSTREAM_HPP
#include <string>
#include "sockaddr.hpp" #include "sockaddr.hpp"
/** /**
...@@ -119,6 +121,16 @@ public: ...@@ -119,6 +121,16 @@ public:
*/ */
void sendAll(const void *data, size_t len); 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 * @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 * is possible that less than len bytes are received. This call will block
......
...@@ -113,6 +113,11 @@ void TcpStream::sendAll(const void *data, size_t len) ...@@ -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) ssize_t TcpStream::read(void *data, size_t len)
{ {
if (sockfd == 0) if (sockfd == 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment