From 00be314f00ddf282cc2391d754a6de49e23a4eb9 Mon Sep 17 00:00:00 2001
From: Daniel M <daniel.q.mueller@stud.h-da.de>
Date: Tue, 11 May 2021 23:44:55 +0200
Subject: [PATCH] Add sendAllString function for TcpStream

- The sendAllString function sends the provided string bytes
---
 inc/tcpstream.hpp | 12 ++++++++++++
 src/tcpstream.cpp |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/inc/tcpstream.hpp b/inc/tcpstream.hpp
index 05f69c5..63ff1fc 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 b470516..630c928 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)
-- 
GitLab