GUACAMOLE-513: Move sleep to protocol implementations; update comments and headers.

This commit is contained in:
Nick Couchman 2020-03-18 14:49:42 -04:00
parent 3dc2591517
commit 45e46bd245
7 changed files with 38 additions and 26 deletions

View File

@ -17,8 +17,8 @@
* under the License.
*/
#ifndef __GUAC_WOL_CONSTANTS_H
#define __GUAC_WOL_CONSTANTS_H
#ifndef GUAC_WOL_CONSTANTS_H
#define GUAC_WOL_CONSTANTS_H
/**
* Header file that provides constants and defaults related to libguac
@ -29,7 +29,8 @@
/**
* The default broadcast address to which Wake-on-LAN packets will be sent
* if one is not specified.
* if one is not specified, which is the special value for the IPv4 local
* network broadcast.
*/
#define GUAC_WOL_DEFAULT_BROADCAST "255.255.255.255"
@ -39,5 +40,5 @@
*/
#define GUAC_WOL_DEFAULT_WAIT_TIME 60
#endif /* __GUAC_WOL_CONSTANTS_H */
#endif /* GUAC_WOL_CONSTANTS_H */

View File

@ -17,8 +17,8 @@
* under the License.
*/
#ifndef __GUAC_WOL_H
#define __GUAC_WOL_H
#ifndef GUAC_WOL_H
#define GUAC_WOL_H
/**
* Header that provides functions and structures related to Wake-on-LAN
@ -42,15 +42,11 @@
* @param broadcast_addr
* The broadcast address to which to send the magic Wake-on-LAN packet.
*
* @param wait_time
* The number of seconds to pause after sending the packet.
*
* @return
* Zero if the packet is successfully sent to the destination; non-zero
* if the packet cannot be sent.
*/
int guac_wol_wake(const char* mac_addr, const char* broadcast_addr,
const int wait_time);
int guac_wol_wake(const char* mac_addr, const char* broadcast_addr);
#endif /* __GUAC_WOL_H */
#endif /* GUAC_WOL_H */

View File

@ -97,8 +97,7 @@ static ssize_t __guac_wol_send_packet(const char* broadcast_addr,
}
int guac_wol_wake(const char* mac_addr, const char* broadcast_addr,
const int wait_time) {
int guac_wol_wake(const char* mac_addr, const char* broadcast_addr) {
unsigned char wol_packet[102];
unsigned int dest_mac[6];
@ -116,10 +115,6 @@ int guac_wol_wake(const char* mac_addr, const char* broadcast_addr,
/* Send the packet and record bytes sent. */
int bytes_sent = __guac_wol_send_packet(broadcast_addr, wol_packet);
/* Sleep for the specified amount of time to wait for the remote
host to boot. */
sleep(wait_time);
/* Return 0 if bytes were sent, otherwise return an error. */
if (bytes_sent)
return 0;

View File

@ -534,9 +534,14 @@ void* guac_rdp_client_thread(void* data) {
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);
if(guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_wait_time))
/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr))
return NULL;
/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
/* If audio enabled, choose an encoder */

View File

@ -206,9 +206,14 @@ void* ssh_client_thread(void* data) {
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_wait_time))
/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr))
return NULL;
/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
/* Init SSH base libraries */

View File

@ -562,9 +562,14 @@ void* guac_telnet_client_thread(void* data) {
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_wait_time))
/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr))
return NULL;
/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
/* Set up screen recording, if requested */

View File

@ -243,9 +243,14 @@ void* guac_vnc_client_thread(void* data) {
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_wait_time))
/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr))
return NULL;
/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
/* Configure clipboard encoding */