/* * This file is part of the Owl Positioning System (OwlPS). * OwlPS is a project of the University of Franche-Comté * (Université de Franche-Comté), France. */ #include "outputnetworksocket.hh" #include "resultlist.hh" #include "result.hh" #include "posexcept.hh" #include // For perror() using namespace std ; /* *** Constructors *** */ OutputNetworkSocket::~OutputNetworkSocket() { close_socket() ; } /* *** Operations *** */ /** * Normally, the socket is closed automatically by the destructor. Use * this if you want to close the socket prematurely. * #sockfd is set to -1, even in case of error. * @return \em true if the socket were successfully closed or were not * opened. * @return \em false in case of error. */ bool OutputNetworkSocket::close_socket() { if (sockfd >= 0) { if (close(sockfd)) { perror("Cannot close network socket") ; return false ; } sockfd = -1 ; } return true ; } void OutputNetworkSocket::write(const Result &result) { send_data(result.to_csv()) ; } void OutputNetworkSocket::write(const ResultList &results) { if (! results.empty()) send_data(results.to_csv()) ; }