libt2n: (gerd) fixes & testcase
[libt2n] / src / socket_handler.cpp
index 4fa27d0..6f9df07 100644 (file)
@@ -34,6 +34,7 @@
 #include <grp.h>
 
 #include <sstream>
+#include <iostream>
 
 #include "socket_handler.hxx"
 #include "t2n_exception.hxx"
@@ -106,9 +107,18 @@ void socket_handler::set_socket_options(int sock)
 
 void socket_handler::close()
 {
+    // graceful shutdown
+    shutdown(sock,SHUT_RDWR);
     ::close(sock);
 }
 
+bool socket_handler::is_closed()
+{
+    int r=fcntl(sock,F_GETFL);
+
+    return !(r & O_ACCMODE);
+}
+
 bool socket_handler::data_waiting(long long usec_timeout)
 {
     // just our socket
@@ -191,7 +201,7 @@ bool socket_handler::fill_buffer(std::string& buffer)
         return false;
 }
 
-void socket_handler::write(const std::string& data)
+void socket_handler::socket_write(const std::string& data)
 {
     int offset = 0;
     while (offset < data.size())