From c61c4b3a2253892632a0440762a1306464e0b35b Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 18 Aug 2011 21:36:42 +0200 Subject: [PATCH] [Positioning] UDP & TCPEvAAL: send '\0' Send the final null character of the CSV string. --- owlps-positioning/src/outputtcpsocketevaal.cc | 5 +++-- owlps-positioning/src/outputudpsocket.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/owlps-positioning/src/outputtcpsocketevaal.cc b/owlps-positioning/src/outputtcpsocketevaal.cc index 68b0d24..ebec47e 100644 --- a/owlps-positioning/src/outputtcpsocketevaal.cc +++ b/owlps-positioning/src/outputtcpsocketevaal.cc @@ -123,8 +123,9 @@ area_of_interest_number(const Point3D &position) const */ bool OutputTCPSocketEvAAL::send_data(const string &data) const { - ssize_t nsent = send(sockfd, data.c_str(), data.size(), 0) ; - if (nsent != static_cast(data.size())) + unsigned int data_len = data.size() + 1 ; // +1 for the '\0' + ssize_t nsent = send(sockfd, data.c_str(), data_len, 0) ; + if (nsent != static_cast(data_len)) { perror("Error sending result data through the TCPEvAAL socket") ; return false ; diff --git a/owlps-positioning/src/outputudpsocket.cc b/owlps-positioning/src/outputudpsocket.cc index ebc8350..1984e04 100644 --- a/owlps-positioning/src/outputudpsocket.cc +++ b/owlps-positioning/src/outputudpsocket.cc @@ -45,10 +45,11 @@ bool OutputUDPSocket::init_socket() */ bool OutputUDPSocket::send_data(const string &data) const { - ssize_t nsent = sendto(sockfd, data.c_str(), data.size(), 0, + unsigned int data_len = data.size() + 1 ; // +1 for the '\0' + ssize_t nsent = sendto(sockfd, data.c_str(), data_len, 0, (struct sockaddr *) &server_info, sizeof(server_info)) ; - if (nsent != static_cast(data.size())) + if (nsent != static_cast(data_len)) { perror("Error sending result data through the UDP socket") ; return false ;