From 3a4359b248742c4d08d00c06badcb346d4a19528 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 29 Jun 2006 21:04:33 +0000 Subject: [PATCH] condvar ->cond Added silc_mime_steal_data. --- lib/silcutil/DIRECTORY | 2 +- lib/silcutil/{silccondvar.h => silccond.h} | 68 +++++++++++----------- lib/silcutil/silcmime.c | 22 ++++++- lib/silcutil/silcmime.h | 18 +++++- lib/silcutil/silcsocketstream.h | 20 ++++++- lib/silcutil/unix/silcunixthread.c | 18 +++--- lib/silcutil/win32/silcwin32thread.c | 20 +++---- 7 files changed, 108 insertions(+), 60 deletions(-) rename lib/silcutil/{silccondvar.h => silccond.h} (65%) diff --git a/lib/silcutil/DIRECTORY b/lib/silcutil/DIRECTORY index d72eb1aa..6aa43e1a 100644 --- a/lib/silcutil/DIRECTORY +++ b/lib/silcutil/DIRECTORY @@ -9,7 +9,7 @@ @LINK=silcmemory.html:SILC Memory Interface @LINK=silcthread.html:SILC Thread Interface @LINK=silcmutex.html:SILC Mutex Interface -@LINK=silccondvar.html:SILC Conditional Variable Interface +@LINK=silccond.html:SILC Conditional Variable Interface @LINK=silcnet.html:SILC Network Interface @LINK=silcschedule.html:SILC Schedule Interface @LINK=silcsockconn.html:SILC Socket Interface diff --git a/lib/silcutil/silccondvar.h b/lib/silcutil/silccond.h similarity index 65% rename from lib/silcutil/silccondvar.h rename to lib/silcutil/silccond.h index ada9007e..25f7c92c 100644 --- a/lib/silcutil/silccondvar.h +++ b/lib/silcutil/silccond.h @@ -1,6 +1,6 @@ /* - silccondvar.h + silccond.h Author: Pekka Riikonen @@ -27,45 +27,45 @@ * ***/ -#ifndef SILCCONDVAR_H -#define SILCCONDVAR_H +#ifndef SILCCOND_H +#define SILCCOND_H -/****s* silcutil/SilcCondVarAPI/SilcCondVar +/****s* silcutil/SilcCondAPI/SilcCond * * NAME * - * typedef struct SilcCondVarStruct *SilcCondVar; + * typedef struct SilcCondStruct *SilcCond; * * DESCRIPTION * * This context is the actual conditional variable and is allocated - * by silc_condvar_alloc and given as argument to all silc_condvar_* - * functions. It is freed by the silc_condvar_free function. + * by silc_cond_alloc and given as argument to all silc_cond_* + * functions. It is freed by the silc_cond_free function. * ***/ -typedef struct SilcCondVarStruct *SilcCondVar; +typedef struct SilcCondStruct *SilcCond; -/****s* silcutil/SilcCondVarAPI/silc_condvar_alloc +/****s* silcutil/SilcCondAPI/silc_cond_alloc * * SYNOPSIS * - * SilcBool silc_condvar_alloc(SilcCondVar *cond); + * SilcBool silc_cond_alloc(SilcCond *cond); * * DESCRIPTION * * Allocates SILC Conditional variable context. The conditional must * be allocated before it can be used. It is freed by the - * silc_condvar_free function. This returns TRUE and allocated + * silc_cond_free function. This returns TRUE and allocated * conditional in to the `cond' pointer and FALSE on error. * ***/ -SilcBool silc_condvar_alloc(SilcCondVar *cond); +SilcBool silc_cond_alloc(SilcCond *cond); -/****s* silcutil/SilcCondVarAPI/silc_condvar_free +/****s* silcutil/SilcCondAPI/silc_cond_free * * SYNOPSIS * - * void silc_condvar_free(SilcCondVar cond); + * void silc_cond_free(SilcCond cond); * * DESCRIPTION * @@ -73,13 +73,13 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond); * has no effect. * ***/ -void silc_condvar_free(SilcCondVar cond); +void silc_cond_free(SilcCond cond); -/****s* silcutil/SilcCondVarAPI/silc_condvar_wait +/****s* silcutil/SilcCondAPI/silc_cond_wait * * SYNOPSIS * - * void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex); + * void silc_cond_wait(SilcCond cond, SilcMutex mutex); * * DESCRIPTION * @@ -93,19 +93,18 @@ void silc_condvar_free(SilcCondVar cond); * * silc_mutex_lock(lock); * while (c->a == NULL) - * silc_condvar_wait(cond, lock); + * silc_cond_wait(cond, lock); * ... * silc_mutex_unlock(lock); * ***/ -void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex); +void silc_cond_wait(SilcCond cond, SilcMutex mutex); -/****s* silcutil/SilcCondVarAPI/silc_condvar_timedwait +/****s* silcutil/SilcCondAPI/silc_cond_timedwait * * SYNOPSIS * - * void silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex, - * struct timespec *timeout); + * void silc_cond_timedwait(SilcCond cond, SilcMutex mutex, int timeout); * * DESCRIPTION * @@ -119,41 +118,40 @@ void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex); * state again. * ***/ -SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex, - int timeout); +SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, int timeout); -/****s* silcutil/SilcCondVarAPI/silc_condvar_signal +/****s* silcutil/SilcCondAPI/silc_cond_signal * * SYNOPSIS * - * void silc_condvar_signal(SilcCondVar cond); + * void silc_cond_signal(SilcCond cond); * * DESCRIPTION * * Signals a waiting thread and wakes it up. If there are no waiters * this function has no effect. In case of multiple waiters only one - * is signalled. To signal all of them use silc_condvar_broadcast. + * is signalled. To signal all of them use silc_cond_broadcast. * * NOTES * - * Before calling this function the mutex used with the silc_condvar_wait + * Before calling this function the mutex used with the silc_cond_wait * must be acquired. * * EXAMPLE * * silc_mutex_lock(lock); * c->a = context; - * silc_condvar_signal(cond); + * silc_cond_signal(cond); * silc_mutex_unlock(lock); * ***/ -void silc_condvar_signal(SilcCondVar cond); +void silc_cond_signal(SilcCond cond); -/****s* silcutil/SilcCondVarAPI/silc_condvar_broadcast +/****s* silcutil/SilcCondAPI/silc_cond_broadcast * * SYNOPSIS * - * void silc_condvar_broadcast(SilcCondVar cond); + * void silc_cond_broadcast(SilcCond cond); * * DESCRIPTION * @@ -162,10 +160,10 @@ void silc_condvar_signal(SilcCondVar cond); * * NOTES * - * Before calling this function the mutex used with the silc_condvar_wait + * Before calling this function the mutex used with the silc_cond_wait * must be acquired. * ***/ -void silc_condvar_broadcast(SilcCondVar cond); +void silc_cond_broadcast(SilcCond cond); -#endif /* SILCCONDVAR_H */ +#endif /* SILCCOND_H */ diff --git a/lib/silcutil/silcmime.c b/lib/silcutil/silcmime.c index 5aa66c17..211b36c3 100644 --- a/lib/silcutil/silcmime.c +++ b/lib/silcutil/silcmime.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -729,6 +729,26 @@ const unsigned char *silc_mime_get_data(SilcMime mime, SilcUInt32 *data_len) return mime->data; } +/* Steal data */ + +unsigned char *silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len) +{ + unsigned char *data; + + if (!mime) + return NULL; + + if (data_len) + *data_len = mime->data_len; + + data = mime->data; + + mime->data = NULL; + mime->data_len = 0; + + return data; +} + /* Returns TRUE if partial message */ SilcBool silc_mime_is_partial(SilcMime mime) diff --git a/lib/silcutil/silcmime.h b/lib/silcutil/silcmime.h index 649c3d36..653a6625 100644 --- a/lib/silcutil/silcmime.h +++ b/lib/silcutil/silcmime.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -290,6 +290,22 @@ void silc_mime_add_data(SilcMime mime, const unsigned char *data, ***/ const unsigned char *silc_mime_get_data(SilcMime mime, SilcUInt32 *data_len); +/****f* silcutil/SILCMIMEAPI/silc_mime_steal_data + * + * SYNOPSIS + * + * unsigned char * + * silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len); + * + * DESCRIPTION + * + * Returns the MIME data from the `mime' message. The data will be + * removed from the `mime' and the caller is responsible of freeing the + * returned pointer. + * + ***/ +unsigned char *silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len); + /****f* silcutil/SILCMIMEAPI/silc_mime_is_partial * * SYNOPSIS diff --git a/lib/silcutil/silcsocketstream.h b/lib/silcutil/silcsocketstream.h index a83a44b7..08dbbcc1 100644 --- a/lib/silcutil/silcsocketstream.h +++ b/lib/silcutil/silcsocketstream.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -69,7 +69,7 @@ typedef enum { * * Callback function of this type is called after the socket stream * creation is completed. If the `stream' is NULL the socket stream could - * not be created of the socket connection is not otherwise allowed. The + * not be created or the socket connection is not otherwise allowed. The * `status' will indicate the error status. The `stream' is socket stream * representing the socket connection and silc_socket_stream_* functions * can be used to access the stream. All other silc_stream_* functions @@ -99,7 +99,7 @@ typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status, * and silc_stream_read. The creation process is asynchronous since * socket connection information, such as hostname and IP address are * resolved, so SilcAsyncOperation is returned which can be used to cancel - * the creationg process. The `callback' will be called to return the + * the creation process. The `callback' will be called to return the * created socket stream. To destroy the stream call silc_stream_destroy. * * If the `lookup' is TRUE then this will performed IP and hostname lookup @@ -117,6 +117,20 @@ silc_socket_stream_create(int sock, SilcBool lookup, SilcSocketStreamCallback callback, void *context); +SilcAsyncOperation +silc_socket_tcp_stream_create(int sock, SilcBool lookup, + SilcBool require_fqdn, + SilcSchedule schedule, + SilcSocketStreamCallback callback, + void *context); + +SilcAsyncOperation +silc_socket_udp_stream_create(int sock, SilcBool lookup, + SilcBool require_fqdn, + SilcSchedule schedule, + SilcSocketStreamCallback callback, + void *context); + /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_get_info * * SYNOPSIS diff --git a/lib/silcutil/unix/silcunixthread.c b/lib/silcutil/unix/silcunixthread.c index b32f61d6..3c5cb659 100644 --- a/lib/silcutil/unix/silcunixthread.c +++ b/lib/silcutil/unix/silcunixthread.c @@ -153,10 +153,10 @@ void silc_mutex_unlock(SilcMutex mutex) } -/**************************** SILC CondVar API ******************************/ +/**************************** SILC Cond API ******************************/ /* SILC Conditional Variable context */ -struct SilcCondVarStruct { +struct SilcCondStruct { #ifdef SILC_THREADS pthread_cond_t cond; #else @@ -164,7 +164,7 @@ struct SilcCondVarStruct { #endif /* SILC_THREADS*/ }; -SilcBool silc_condvar_alloc(SilcCondVar *cond) +SilcBool silc_cond_alloc(SilcCond *cond) { #ifdef SILC_THREADS *cond = silc_calloc(1, sizeof(**cond)); @@ -177,7 +177,7 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond) #endif /* SILC_THREADS*/ } -void silc_condvar_free(SilcCondVar cond) +void silc_cond_free(SilcCond cond) { #ifdef SILC_THREADS pthread_cond_destroy(&cond->cond); @@ -185,29 +185,29 @@ void silc_condvar_free(SilcCondVar cond) #endif /* SILC_THREADS*/ } -void silc_condvar_signal(SilcCondVar cond) +void silc_cond_signal(SilcCond cond) { #ifdef SILC_THREADS pthread_cond_signal(&cond->cond); #endif /* SILC_THREADS*/ } -void silc_condvar_broadcast(SilcCondVar cond) +void silc_cond_broadcast(SilcCond cond) { #ifdef SILC_THREADS pthread_cond_broadcast(&cond->cond); #endif /* SILC_THREADS*/ } -void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex) +void silc_cond_wait(SilcCond cond, SilcMutex mutex) { #ifdef SILC_THREADS pthread_cond_wait(&cond->cond, &mutex->mutex); #endif /* SILC_THREADS*/ } -SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex, - int timeout) +SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, + int timeout) { #ifdef SILC_THREADS struct timespec t; diff --git a/lib/silcutil/win32/silcwin32thread.c b/lib/silcutil/win32/silcwin32thread.c index f55a55ac..0d82f559 100644 --- a/lib/silcutil/win32/silcwin32thread.c +++ b/lib/silcutil/win32/silcwin32thread.c @@ -205,10 +205,10 @@ void silc_mutex_unlock(SilcMutex mutex) } -/**************************** SILC CondVar API ******************************/ +/**************************** SILC Cond API ******************************/ /* SILC Conditional Variable context */ -struct SilcCondVarStruct { +struct SilcCondStruct { #ifdef SILC_THREADS HANDLE event; #endif /* SILC_THREADS*/ @@ -216,7 +216,7 @@ struct SilcCondVarStruct { unsigned int signal : 1; }; -SilcBool silc_condvar_alloc(SilcCondVar *cond) +SilcBool silc_cond_alloc(SilcCond *cond) { #ifdef SILC_THREADS *cond = silc_calloc(1, sizeof(**cond)); @@ -229,7 +229,7 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond) #endif /* SILC_THREADS*/ } -void silc_condvar_free(SilcCondVar cond) +void silc_cond_free(SilcCond cond) { #ifdef SILC_THREADS CloseHandle(cond->event); @@ -237,7 +237,7 @@ void silc_condvar_free(SilcCondVar cond) #endif /* SILC_THREADS*/ } -void silc_condvar_signal(SilcCondVar cond) +void silc_cond_signal(SilcCond cond) { #ifdef SILC_THREADS cond->signal = TRUE; @@ -245,7 +245,7 @@ void silc_condvar_signal(SilcCondVar cond) #endif /* SILC_THREADS*/ } -void silc_condvar_broadcast(SilcCondVar cond) +void silc_cond_broadcast(SilcCond cond) { #ifdef SILC_THREADS cond->signal = TRUE; @@ -253,15 +253,15 @@ void silc_condvar_broadcast(SilcCondVar cond) #endif /* SILC_THREADS*/ } -void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex) +void silc_cond_wait(SilcCond cond, SilcMutex mutex) { #ifdef SILC_THREADS - silc_condvar_timedwait(cond, mutex, NULL); + silc_cond_timedwait(cond, mutex, NULL); #endif /* SILC_THREADS*/ } -SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex, - int timeout) +SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, + int timeout) { #ifdef SILC_THREADS DWORD ret, t = INFINITE; -- 2.24.0