aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-01-09 10:21:03 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-01-09 10:21:03 +0000
commitf152f23a680670e72e230d6247a2ed4552750480 (patch)
tree3c79410572a7327fbf2fdf2ef6d4c72645610562 /lib
parent24e78b35717262af19fa0d26892dde08f7ab1473 (diff)
Updated more and now looks and and the API possibly works almost like the
design document specifies. There is still no code inside that uses this.
Diffstat (limited to 'lib')
-rw-r--r--lib/share.c177
-rw-r--r--lib/share.h11
2 files changed, 81 insertions, 107 deletions
diff --git a/lib/share.c b/lib/share.c
index f0203f1a9..4d12b66e5 100644
--- a/lib/share.c
+++ b/lib/share.c
@@ -24,141 +24,122 @@
#include "setup.h"
#include <stdlib.h>
#include <curl/curl.h>
-#include "share.h"
#include "urldata.h"
+#include "share.h"
/* The last #include file should be: */
#ifdef MALLOCDEBUG
#include "memdebug.h"
#endif
-#define CURL_SHARE_SET_LOCKED(__share, __type) ((__share)->locked += (__type))
-#define CURL_SHARE_SET_UNLOCKED(__share, __type) ((__share)->locked -= (__type))
-
-#define CURL_SHARE_SET_USED(__share, __type) ((__share)->specifier += (__type))
-#define CURL_SHARE_SET_UNUSED(__share, __type) ((__share)->specifier -= (__type))
-#define CURL_SHARE_IS_USED(__share, __type) ((__share)->specifier & (__type))
-#define CURL_SHARE_IS_LOCKED(__share, __type) ((__share)->locked & (__type))
-
-#define CURL_SHARE_IS_DIRTY(__share) ((__share)->dirty)
-
-#define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share)
-
CURLSH *
-curl_share_init (void)
+curl_share_init(void)
{
- curl_share *share = (curl_share *) malloc (sizeof (curl_share));
- if (share) {
- memset (share, 0, sizeof (curl_share));
- }
+ struct Curl_share *share =
+ (struct Curl_share *)malloc(sizeof(struct Curl_share));
+ if (share)
+ memset (share, 0, sizeof(struct Curl_share));
return share;
}
-CURLcode
-curl_share_setopt (curl_share *share, curl_lock_type option, int enable)
+CURLSHcode
+curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
{
- if (CURL_SHARE_IS_DIRTY(share)) {
- return CURLE_SHARE_IN_USE;
+ struct Curl_share *share = (struct Curl_share *)sh;
+ va_list param;
+ int type;
+ curl_lock_function lockfunc;
+ curl_unlock_function unlockfunc;
+ void *ptr;
+
+ if (share->dirty)
+ /* don't allow setting options while one or more handles are already
+ using this share */
+ return CURLSHE_IN_USE;
+
+ va_start(param, option);
+
+ switch(option) {
+ case CURLSHOPT_SHARE:
+ /* this is a type this share will share */
+ type = va_arg(param, int);
+ share->specifier |= (1<<type);
+ break;
+
+ case CURLSHOPT_UNSHARE:
+ /* this is a type this share will no longer share */
+ type = va_arg(param, int);
+ share->specifier &= ~(1<<type);
+ break;
+
+ case CURLSHOPT_LOCKFUNC:
+ lockfunc = va_arg(param, curl_lock_function);
+ share->lockfunc = lockfunc;
+ break;
+
+ case CURLSHOPT_UNLOCKFUNC:
+ unlockfunc = va_arg(param, curl_unlock_function);
+ share->unlockfunc = unlockfunc;
+ break;
+
+ case CURLSHOPT_USERDATA:
+ ptr = va_arg(param, void *);
+ share->clientdata = ptr;
+ break;
+
+ default:
+ return CURLSHE_BAD_OPTION;
}
- if (enable) {
- CURL_SHARE_SET_USED (share, option);
- }
- else {
- CURL_SHARE_SET_UNUSED (share, option);
- }
-
- return CURLE_OK;
-}
-
-CURLcode
-curl_share_set_lock_function (curl_share *share, curl_lock_function lock)
-{
- if (CURL_SHARE_IS_DIRTY(share)) {
- return CURLE_SHARE_IN_USE;
- }
-
- share->lockfunc = lock;
- return CURLE_OK;
+ return CURLSHE_OK;
}
-CURLcode
-curl_share_set_unlock_function (curl_share *share, curl_unlock_function unlock)
+CURLSHcode curl_share_cleanup(CURLSH *sh)
{
- if (CURL_SHARE_IS_DIRTY(share)) {
- return CURLE_SHARE_IN_USE;
- }
+ struct Curl_share *share = (struct Curl_share *)sh;
+ if (share->dirty)
+ return CURLSHE_IN_USE;
- share->unlockfunc = unlock;
- return CURLE_OK;
+ free (share);
+
+ return CURLSHE_OK;
}
-CURLcode
-curl_share_set_lock_data (curl_share *share, void *data)
-{
- if (CURL_SHARE_IS_DIRTY(share)) {
- return CURLE_SHARE_IN_USE;
- }
-
- share->clientdata = data;
- return CURLE_OK;
-}
-Curl_share_error
-Curl_share_acquire_lock (CURL *handle, curl_lock_type type)
+CURLSHcode
+Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type)
{
- curl_share *share = CURL_SHARE_GET (handle);
- if (share == NULL) {
- return SHARE_ERROR_INVALID;
- }
+ struct Curl_share *share = data->share;
- if (! (share->specifier & type)) {
- return SHARE_ERROR_NOT_REGISTERED;
- }
+ if (share == NULL)
+ return CURLSHE_INVALID;
- if (CURL_SHARE_IS_LOCKED (share, type)) {
- return SHARE_ERROR_OK;
+ if(share->specifier & (1<<type)) {
+ share->lockfunc (data, type, CURL_LOCK_ACCESS_SINGLE, share->clientdata);
+ share->locked |= (1<<type);
}
+ /* else if we don't share this, pretend successful lock */
- share->lockfunc (handle, type, share->clientdata);
- CURL_SHARE_SET_LOCKED (share, type);
-
- return SHARE_ERROR_OK;
+ return CURLSHE_OK;
}
-Curl_share_error
-Curl_share_release_lock (CURL *handle, curl_lock_type type)
+CURLSHcode
+Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type)
{
- curl_share *share = CURL_SHARE_GET(handle);
- if (share == NULL) {
- return SHARE_ERROR_INVALID;
- }
+ struct Curl_share *share = data->share;
- if (! (share->specifier & type)) {
- return SHARE_ERROR_NOT_REGISTERED;
- }
+ if (share == NULL)
+ return CURLSHE_INVALID;
- if (!CURL_SHARE_IS_LOCKED (share, type)) {
- return SHARE_ERROR_OK;
+ if(share->specifier & (1<<type)) {
+ share->unlockfunc (data, type, share->clientdata);
+ share->locked &= ~(1<<type);
}
- share->unlockfunc (handle, type, share->clientdata);
- CURL_SHARE_SET_UNLOCKED (share, type);
-
- return SHARE_ERROR_OK;
+ return CURLSHE_OK;
}
-CURLcode curl_share_destroy (curl_share *share)
-{
- if (CURL_SHARE_IS_DIRTY(share)) {
- return CURLE_SHARE_IN_USE;
- }
-
- free (share);
-
- return CURLE_OK;
-}
/*
* local variables:
diff --git a/lib/share.h b/lib/share.h
index 75a32961f..fdd6ec555 100644
--- a/lib/share.h
+++ b/lib/share.h
@@ -27,13 +27,6 @@
#include "setup.h"
#include <curl/curl.h>
-typedef enum {
- SHARE_ERROR_OK = 0,
- SHARE_ERROR_INVALID,
- SHARE_ERROR_NOT_REGISTERED,
- SHARE_ERROR_LAST
-} Curl_share_error;
-
/* this struct is libcurl-private, don't export details */
struct Curl_share {
unsigned int specifier;
@@ -45,8 +38,8 @@ struct Curl_share {
void *clientdata;
};
-Curl_share_error Curl_share_aquire_lock (CURL *, curl_lock_data);
-Curl_share_error Curl_share_release_lock (CURL *, curl_lock_data);
+CURLSHcode Curl_share_aquire_lock (struct SessionHandle *, curl_lock_data);
+CURLSHcode Curl_share_release_lock (struct SessionHandle *, curl_lock_data);
#endif /* __CURL_SHARE_H */