[lib-client] Add "verbose" parameters

owl_send_request() and owl_send_packet() get a boolean "verbose"
parameter that allow to enable or disable message display on run-time
and allow to get rid of the OWLPS_DEBUG compile-time option.
This commit is contained in:
Matteo Cypriani 2013-06-07 17:01:04 -04:00
parent b859734d23
commit e114a6997a
4 changed files with 27 additions and 19 deletions

View File

@ -103,25 +103,27 @@ void owl_use_iface(const int sockfd, const char *const iface)
* @param[in] packet_size The buffer's size.
* @param[in] nb_pkt Number of packets to transmit.
* @param[in] delay Delay between two transmissions, in milliseconds.
* @param[in] verbose If `true`, a "progress bar" will be printed on the
* standard output.
*/
void owl_send_request(const int sockfd,
const struct sockaddr_in *const server,
const void *const packet,
const uint_fast16_t packet_size,
const uint_fast16_t nb_pkt,
const uint_fast32_t delay)
const uint_fast32_t delay,
const bool verbose)
{
uint_fast16_t i ;
if (nb_pkt == 0 || !owl_run)
return ;
#ifdef OWLPS_DEBUG
printf("Sent packets: ") ;
#endif // OWLPS_DEBUG
if (verbose)
printf("Sent packets: ") ;
// Transmit first packet:
owl_send_packet(sockfd, server, packet, packet_size) ;
owl_send_packet(sockfd, server, packet, packet_size, verbose) ;
// Transmit remaining packets (if any):
for (i = 1 ; i < nb_pkt ; ++i)
@ -132,12 +134,11 @@ void owl_send_request(const int sockfd,
break ;
// Update the packet number:
memcpy(&((char*) packet)[1], &current_pkt, sizeof(uint16_t)) ;
owl_send_packet(sockfd, server, packet, packet_size) ;
owl_send_packet(sockfd, server, packet, packet_size, verbose) ;
}
#ifdef OWLPS_DEBUG
putchar('\n') ;
#endif // OWLPS_DEBUG
if (verbose)
putchar('\n') ;
}
@ -146,11 +147,14 @@ void owl_send_request(const int sockfd,
* Transmits a single packet of a request.
* See the documentation of the `owl_send_request()` function for an
* explanation on the parameters.
* When `verbose` if `true`, a dot will be printed on the standard output
* and the standard output will be flushed.
*/
void owl_send_packet(const int sockfd,
const struct sockaddr_in *const server,
const void *const packet,
const uint_fast16_t packet_size)
const uint_fast16_t packet_size,
const bool verbose)
{
ssize_t nsent = sendto(sockfd, packet, packet_size, 0,
(struct sockaddr *) server,
@ -161,8 +165,9 @@ void owl_send_packet(const int sockfd,
exit(OWL_ERR_SOCKET_SEND) ;
}
#ifdef OWLPS_DEBUG
putchar('.') ;
fflush(stdout) ;
#endif // OWLPS_DEBUG
if (verbose)
{
putchar('.') ;
fflush(stdout) ;
}
}

View File

@ -40,11 +40,13 @@ void owl_send_request(const int sockfd,
const void *const packet,
const uint_fast16_t packet_size,
const uint_fast16_t nb_pkt,
const uint_fast32_t delay) ;
const uint_fast32_t delay,
const bool verbose) ;
void owl_send_packet(const int sockfd,
const struct sockaddr_in *const server,
const void *const packet,
const uint_fast16_t packet_size) ;
const uint_fast16_t packet_size,
const bool verbose) ;
#endif // _LIBOWLPS_CLIENT_

View File

@ -473,7 +473,7 @@ void send_request()
{
make_packet() ;
owl_send_request(sockfd, &server, packet, packet_size,
options.nb_pkt, options.delay) ;
options.nb_pkt, options.delay, options.verbose) ;
free(packet) ;
}

View File

@ -1424,7 +1424,7 @@ void* autocalibrate_hello(void *NULL_value)
while (owl_run)
{
owl_send_packet(send_sockfd, &serv,
&message, sizeof(message)) ;
&message, sizeof(message), VERBOSE_INFO) ;
sleep(GET_AUTOCALIBRATION_HELLO_DELAY()) ;
}
@ -1506,7 +1506,8 @@ void send_autocalibration_request()
&autocalibration_send_server,
packet, packet_size,
GET_AUTOCALIBRATION_NBPKT(),
GET_AUTOCALIBRATION_DELAY()) ;
GET_AUTOCALIBRATION_DELAY(),
VERBOSE_INFO) ;
free(packet) ;
}