* timeframe, server messages will not be handled until a sync instruction is
* received from the client.
*/
-#define GUAC_SYNC_THRESHOLD 500
+#define GUACD_SYNC_THRESHOLD 500
/**
* The time to allow between server sync messages in milliseconds. A sync
- * message from the server will be sent every GUAC_SYNC_FREQUENCY milliseconds.
+ * message from the server will be sent every GUACD_SYNC_FREQUENCY milliseconds.
* As this will induce a response from a client that is not malfunctioning,
* this is used to detect when a client has died. This must be set to a
* reasonable value to avoid clients being disconnected unnecessarily due
* to timeout.
*/
-#define GUAC_SYNC_FREQUENCY 5000
+#define GUACD_SYNC_FREQUENCY 5000
/**
* The amount of time to wait after handling server messages. If a client
* are being handled, there will be a pause of this many milliseconds before
* the next call to the message handler.
*/
-#define GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY 50
+#define GUACD_MESSAGE_HANDLE_FREQUENCY 50
+
/**
* The number of milliseconds to wait for messages in any phase before
* timing out and closing the connection with an error.
*/
-#define GUAC_TIMEOUT 15000
+#define GUACD_TIMEOUT 15000
/**
* The number of microseconds to wait for messages in any phase before
* timing out and closing the conncetion with an error. This is always
- * equal to GUAC_TIMEOUT * 1000.
+ * equal to GUACD_TIMEOUT * 1000.
*/
-#define GUAC_USEC_TIMEOUT (GUAC_TIMEOUT*1000)
+#define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
void guac_client_stop(guac_client* client);
/* Occasionally ping client with repeat of last sync */
guac_timestamp timestamp = guac_protocol_get_timestamp();
- if (timestamp - last_ping_timestamp > GUAC_SYNC_FREQUENCY) {
+ if (timestamp - last_ping_timestamp > GUACD_SYNC_FREQUENCY) {
/* Record time of last synnc */
last_ping_timestamp = timestamp;
/* Only handle messages if synced within threshold */
if (client->last_sent_timestamp - client->last_received_timestamp
- < GUAC_SYNC_THRESHOLD) {
+ < GUACD_SYNC_THRESHOLD) {
int retval = client->handle_messages(client);
if (retval) {
/* Do not spin while waiting for old sync */
else
- __guacd_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
+ __guacd_sleep(GUACD_MESSAGE_HANDLE_FREQUENCY);
}
/* If no message handler, just sleep until next sync ping */
else
- __guacd_sleep(GUAC_SYNC_FREQUENCY);
+ __guacd_sleep(GUACD_SYNC_FREQUENCY);
} /* End of output loop */
/* Read instruction */
guac_instruction* instruction =
- guac_protocol_read_instruction(socket, GUAC_USEC_TIMEOUT);
+ guac_protocol_read_instruction(socket, GUACD_USEC_TIMEOUT);
/* Stop on error */
if (instruction == NULL) {
/* Get protocol from select instruction */
select = guac_protocol_expect_instruction(
- socket, GUAC_USEC_TIMEOUT, "select");
+ socket, GUACD_USEC_TIMEOUT, "select");
if (select == NULL) {
/* Log error */
/* Get args from connect instruction */
connect = guac_protocol_expect_instruction(
- socket, GUAC_USEC_TIMEOUT, "connect");
+ socket, GUACD_USEC_TIMEOUT, "connect");
if (connect == NULL) {
/* Log error */
}
/* Fork into background */
-#ifdef HAVE_FORK
daemon_pid = fork();
/* If error, fail */
exit(EXIT_SUCCESS);
}
-#else
- daemon_pid = getpid();
- syslog(LOG_INFO, "fork() not defined at compile time.");
- syslog(LOG_INFO, "guacd running in foreground only.");
-#endif
+
+ /* Open log */
+ openlog(NULL, LOG_PID, LOG_DAEMON);
/* Otherwise, this is the daemon */
syslog(LOG_INFO, "Listening on port %i", listen_port);
/* Daemon loop */
for (;;) {
-#ifdef HAVE_FORK
pid_t child_pid;
-#else
- guac_thread_t thread;
-#endif
client_thread_data* data;
/* Listen for connections */
data->fd = connected_socket_fd;
/*
- * Once connection is accepted, send child into background, whether through
- * fork() or through creating a thread. If thead support is not present on
- * the platform, guacd will still work, but will only be able to handle one
- * connection at a time.
- */
-
-#ifdef HAVE_FORK
-
- /*** FORK ***/
-
- /*
+ * Once connection is accepted, send child into background.
+ *
* Note that we prefer fork() over threads for connection-handling
* processes as they give each connection its own memory area, and
* isolate the main daemon and other connections from errors in any
syslog(LOG_ERR, "Error closing daemon reference to child descriptor: %s", strerror(errno));
}
-#else
-
- if (guac_thread_create(&thread, start_client_thread, (void*) data))
- syslog(LOG_ERR, "Could not create client thread: %s", strerror(errno));
-
-#endif
-
}
/* Close socket */