Removed thread.*, using pthreads directly. More renaming of guac to guacd.
This commit is contained in:
parent
7a18b397de
commit
fb74c24ec1
@ -42,8 +42,8 @@ AM_CFLAGS = -Werror -Wall -pedantic -Iinclude
|
|||||||
sbin_PROGRAMS = guacd
|
sbin_PROGRAMS = guacd
|
||||||
init_SCRIPTS = init.d/guacd
|
init_SCRIPTS = init.d/guacd
|
||||||
|
|
||||||
noinst_HEADERS = include/client.h include/thread.h include/log.h
|
noinst_HEADERS = include/client.h include/log.h
|
||||||
guacd_SOURCES = src/daemon.c src/client.c src/thread.c src/log.c
|
guacd_SOURCES = src/daemon.c src/client.c src/log.c
|
||||||
|
|
||||||
EXTRA_DIST = init.d/guacd.in
|
EXTRA_DIST = init.d/guacd.in
|
||||||
CLEANFILES = $(init_SCRIPTS)
|
CLEANFILES = $(init_SCRIPTS)
|
||||||
|
@ -79,6 +79,6 @@
|
|||||||
*/
|
*/
|
||||||
#define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
|
#define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
|
||||||
|
|
||||||
int guac_start_client(guac_client* client);
|
int guacd_client_start(guac_client* client);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
|
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
|
||||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
* http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing rights and limitations under the
|
|
||||||
* License.
|
|
||||||
*
|
|
||||||
* The Original Code is guacd.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is
|
|
||||||
* Michael Jumper.
|
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
||||||
* the Initial Developer. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
||||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
||||||
* the provisions above, a recipient may use your version of this file under
|
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
#ifndef _GUACD_THREAD_H
|
|
||||||
#define _GUACD_THREAD_H
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides basic cross-platform threads.
|
|
||||||
*
|
|
||||||
* @file thread.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
typedef pthread_t guac_thread;
|
|
||||||
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <process.h>
|
|
||||||
typedef HANDLE guac_thread;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int guac_thread_create(guac_thread* thread, void*(*function)(void*), void* data);
|
|
||||||
void guac_thread_join(guac_thread thread);
|
|
||||||
|
|
||||||
#endif
|
|
@ -37,13 +37,13 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <guacamole/socket.h>
|
#include <guacamole/socket.h>
|
||||||
#include <guacamole/client.h>
|
#include <guacamole/client.h>
|
||||||
#include <guacamole/error.h>
|
#include <guacamole/error.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "thread.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@
|
|||||||
*
|
*
|
||||||
* @param millis The number of milliseconds to sleep.
|
* @param millis The number of milliseconds to sleep.
|
||||||
*/
|
*/
|
||||||
void __guacd_sleep(int millis) {
|
void __guacdd_sleep(int millis) {
|
||||||
|
|
||||||
struct timespec sleep_period;
|
struct timespec sleep_period;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ void __guacd_sleep(int millis) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* __guac_client_output_thread(void* data) {
|
void* __guacd_client_output_thread(void* data) {
|
||||||
|
|
||||||
guac_client* client = (guac_client*) data;
|
guac_client* client = (guac_client*) data;
|
||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
@ -133,13 +133,13 @@ void* __guac_client_output_thread(void* data) {
|
|||||||
|
|
||||||
/* Do not spin while waiting for old sync */
|
/* Do not spin while waiting for old sync */
|
||||||
else
|
else
|
||||||
__guacd_sleep(GUACD_MESSAGE_HANDLE_FREQUENCY);
|
__guacdd_sleep(GUACD_MESSAGE_HANDLE_FREQUENCY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no message handler, just sleep until next sync ping */
|
/* If no message handler, just sleep until next sync ping */
|
||||||
else
|
else
|
||||||
__guacd_sleep(GUACD_SYNC_FREQUENCY);
|
__guacdd_sleep(GUACD_SYNC_FREQUENCY);
|
||||||
|
|
||||||
} /* End of output loop */
|
} /* End of output loop */
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ void* __guac_client_output_thread(void* data) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* __guac_client_input_thread(void* data) {
|
void* __guacd_client_input_thread(void* data) {
|
||||||
|
|
||||||
guac_client* client = (guac_client*) data;
|
guac_client* client = (guac_client*) data;
|
||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
@ -199,25 +199,25 @@ void* __guac_client_input_thread(void* data) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int guac_start_client(guac_client* client) {
|
int guacd_client_start(guac_client* client) {
|
||||||
|
|
||||||
guac_thread input_thread, output_thread;
|
pthread_t input_thread, output_thread;
|
||||||
|
|
||||||
if (guac_thread_create(&output_thread, __guac_client_output_thread, (void*) client)) {
|
if (pthread_create(&output_thread, NULL, __guacd_client_output_thread, (void*) client)) {
|
||||||
guac_client_log_error(client, "Unable to start output thread");
|
guac_client_log_error(client, "Unable to start output thread");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guac_thread_create(&input_thread, __guac_client_input_thread, (void*) client)) {
|
if (pthread_create(&input_thread, NULL, __guacd_client_input_thread, (void*) client)) {
|
||||||
guac_client_log_error(client, "Unable to start input thread");
|
guac_client_log_error(client, "Unable to start input thread");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
guac_thread_join(output_thread);
|
pthread_join(output_thread, NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for I/O threads */
|
/* Wait for I/O threads */
|
||||||
guac_thread_join(input_thread);
|
pthread_join(input_thread, NULL);
|
||||||
guac_thread_join(output_thread);
|
pthread_join(output_thread, NULL);
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -172,7 +172,7 @@ void* start_client_thread(void* data) {
|
|||||||
|
|
||||||
/* Start client threads */
|
/* Start client threads */
|
||||||
syslog(LOG_INFO, "Starting client");
|
syslog(LOG_INFO, "Starting client");
|
||||||
if (guac_start_client(client))
|
if (guacd_client_start(client))
|
||||||
syslog(LOG_ERR, "Client finished abnormally");
|
syslog(LOG_ERR, "Client finished abnormally");
|
||||||
else
|
else
|
||||||
syslog(LOG_INFO, "Client finished normally");
|
syslog(LOG_INFO, "Client finished normally");
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
|
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
|
||||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
* http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing rights and limitations under the
|
|
||||||
* License.
|
|
||||||
*
|
|
||||||
* The Original Code is guacd.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is
|
|
||||||
* Michael Jumper.
|
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
||||||
* the Initial Developer. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
||||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
||||||
* the provisions above, a recipient may use your version of this file under
|
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
#include "thread.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
#include <pthread.h>
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
#include <windows.h>
|
|
||||||
#include <process.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int guac_thread_create(guac_thread* thread, void*(*function)(void*), void* data) {
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
return pthread_create(thread, NULL, function, data);
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
*thread = (guac_thread) _beginthreadex(NULL, 0,
|
|
||||||
(unsigned(__stdcall*)(void*)) function, data,
|
|
||||||
0 /* Create running */, NULL);
|
|
||||||
if (thread == 0)
|
|
||||||
return errno;
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void guac_thread_join(guac_thread thread) {
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
pthread_join(thread, NULL);
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
WaitForSingleObject(thread, INFINITE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user