[Positioning] UDP & TCPEvAAL: send '\0'

Send the final null character of the CSV string.
This commit is contained in:
Matteo Cypriani 2011-08-18 21:36:42 +02:00
parent de74213102
commit c61c4b3a22
2 changed files with 6 additions and 4 deletions

View File

@ -123,8 +123,9 @@ area_of_interest_number(const Point3D &position) const
*/ */
bool OutputTCPSocketEvAAL::send_data(const string &data) const bool OutputTCPSocketEvAAL::send_data(const string &data) const
{ {
ssize_t nsent = send(sockfd, data.c_str(), data.size(), 0) ; unsigned int data_len = data.size() + 1 ; // +1 for the '\0'
if (nsent != static_cast<ssize_t>(data.size())) ssize_t nsent = send(sockfd, data.c_str(), data_len, 0) ;
if (nsent != static_cast<ssize_t>(data_len))
{ {
perror("Error sending result data through the TCPEvAAL socket") ; perror("Error sending result data through the TCPEvAAL socket") ;
return false ; return false ;

View File

@ -45,10 +45,11 @@ bool OutputUDPSocket::init_socket()
*/ */
bool OutputUDPSocket::send_data(const string &data) const 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, (struct sockaddr *) &server_info,
sizeof(server_info)) ; sizeof(server_info)) ;
if (nsent != static_cast<ssize_t>(data.size())) if (nsent != static_cast<ssize_t>(data_len))
{ {
perror("Error sending result data through the UDP socket") ; perror("Error sending result data through the UDP socket") ;
return false ; return false ;