Changeset 8:3e143f047f78 in freeDiameter for include/freeDiameter/libfreeDiameter.h
- Timestamp:
- Sep 18, 2009, 6:54:07 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfreeDiameter.h
r7 r8 37 37 * 38 38 * This library is meant to be used by both the freeDiameter daemon and its extensions. 39 *40 39 * It provides the tools to manipulate Diameter messages and related data. 41 *42 40 * This file should always be included as #include <freeDiameter/libfreeDiameter.h> 41 * 42 * The file contains the following parts: 43 * DEBUG 44 * MACROS 45 * THREADS 46 * LISTS 47 * DICTIONARY 48 * SESSIONS 49 * MESSAGES 50 * DISPATCH 51 * QUEUES 43 52 */ 44 53 … … 297 306 #define sSA6 struct sockaddr_in6 298 307 299 /* Dump one sockaddr */300 #define sSA_DUMP ( level, text, sa) { \308 /* Dump one sockaddr Node information */ 309 #define sSA_DUMP_NODE( sa, flag ) { \ 301 310 sSA * __sa = (sSA *)(sa); \ 302 char *__str, __addrbuf[INET6_ADDRSTRLEN];\311 char __addrbuf[INET6_ADDRSTRLEN]; \ 303 312 if (__sa) { \ 304 313 int __rc = getnameinfo(__sa, \ … … 308 317 NULL, \ 309 318 0, \ 310 0); \319 flag); \ 311 320 if (__rc) \ 312 __str = (char *)gai_strerror(__rc);\321 fd_log_debug((char *)gai_strerror(__rc)); \ 313 322 else \ 314 __str = &__addrbuf[0];\323 fd_log_debug(&__addrbuf[0]); \ 315 324 } else { \ 316 __str = "(NULL / ANY)";\325 fd_log_debug("(NULL / ANY)"); \ 317 326 } \ 318 TRACE_DEBUG(level, text "%s", __str); \319 327 } 328 /* if needed, add sSA_DUMP_SERVICE */ 320 329 321 330 /* The sockaddr length of a sSS structure */ … … 2275 2284 2276 2285 /*============================================================*/ 2277 /* MESSAGE QUEUES*/2286 /* QUEUES */ 2278 2287 /*============================================================*/ 2279 2288 2280 /* Management of queues of messages */2281 2282 /* A messagequeue is an opaque object */2283 struct mqueue;2284 2285 /* 2286 * FUNCTION: fd_ mq_new2287 * 2288 * PARAMETERS: 2289 * queue : Upon success, a pointer to the new messagequeue is saved here.2290 * 2291 * DESCRIPTION: 2292 * Create a new empty messagequeue.2289 /* Management of FIFO queues of elements */ 2290 2291 /* A queue is an opaque object */ 2292 struct fifo; 2293 2294 /* 2295 * FUNCTION: fd_fifo_new 2296 * 2297 * PARAMETERS: 2298 * queue : Upon success, a pointer to the new queue is saved here. 2299 * 2300 * DESCRIPTION: 2301 * Create a new empty queue. 2293 2302 * 2294 2303 * RETURN VALUE : 2295 * 0 : The messagequeue has been initialized successfully.2304 * 0 : The queue has been initialized successfully. 2296 2305 * EINVAL : The parameter is invalid. 2297 2306 * ENOMEM : Not enough memory to complete the creation. 2298 2307 */ 2299 int fd_ mq_new ( struct mqueue** queue );2300 2301 /* 2302 * FUNCTION: fd_ mq_del2303 * 2304 * PARAMETERS: 2305 * queue : Pointer to an empty messagequeue to delete.2306 * 2307 * DESCRIPTION: 2308 * Destroys a message queue. This is only possible if no thread is waiting for a message,2308 int fd_fifo_new ( struct fifo ** queue ); 2309 2310 /* 2311 * FUNCTION: fd_fifo_del 2312 * 2313 * PARAMETERS: 2314 * queue : Pointer to an empty queue to delete. 2315 * 2316 * DESCRIPTION: 2317 * Destroys a queue. This is only possible if no thread is waiting for an element, 2309 2318 * and the queue is empty. 2310 2319 * 2311 2320 * RETURN VALUE: 2312 * 0 : The messagequeue has been destroyed successfully.2321 * 0 : The queue has been destroyed successfully. 2313 2322 * EINVAL : The parameter is invalid. 2314 2323 */ 2315 int fd_ mq_del ( struct mqueue** queue );2316 2317 /* 2318 * FUNCTION: fd_ mq_length2319 * 2320 * PARAMETERS: 2321 * queue : The queue from which to retrieve the length.2322 * length : Upon success, the current number of messages in the queue is stored here.2323 * 2324 * DESCRIPTION: 2325 * Retrieve the number of messages pendingin a queue.2324 int fd_fifo_del ( struct fifo ** queue ); 2325 2326 /* 2327 * FUNCTION: fd_fifo_length 2328 * 2329 * PARAMETERS: 2330 * queue : The queue from which to retrieve the number of elements. 2331 * length : Upon success, the current number of elements in the queue is stored here. 2332 * 2333 * DESCRIPTION: 2334 * Retrieve the number of elements in a queue. 2326 2335 * 2327 2336 * RETURN VALUE: … … 2329 2338 * EINVAL : A parameter is invalid. 2330 2339 */ 2331 int fd_ mq_length ( struct mqueue* queue, int * length );2332 int fd_ mq_length_noerr ( struct mqueue * queue ); /* alternate with no error checking*/2333 2334 /* 2335 * FUNCTION: fd_ mq_setthrhd2340 int fd_fifo_length ( struct fifo * queue, int * length ); 2341 int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */ 2342 2343 /* 2344 * FUNCTION: fd_fifo_setthrhd 2336 2345 * 2337 2346 * PARAMETERS: … … 2345 2354 * DESCRIPTION: 2346 2355 * This function allows to adjust the number of producer / consumer threads of a queue. 2347 * If the consumer are slower than the producers, the number of messages in the queue increase.2356 * If the consumer are slower than the producers, the number of elements in the queue increase. 2348 2357 * By setting a "high" value, we allow a callback to be called when this number is too high. 2349 2358 * The typical use would be to create an additional consumer thread in this callback. 2350 2359 * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high 2351 * (the callback itself mayimplement a limit on the number of consumers that can be created)2360 * (the callback itself should implement a limit on the number of consumers that can be created) 2352 2361 * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called 2353 * and would typially stop one of the consumer threads. If the queue continue to reduce, l_cb is again called at (N-2)*high + low,2362 * and would typially stop one of the consumer threads. If the queue continues to reduce, l_cb is again called at (N-2)*high + low, 2354 2363 * and so on. 2355 2364 * … … 2357 2366 * l_cb when the length of the queue is becoming < low. 2358 2367 * 2359 * Note that the callbacks are called synchronously, during fd_ mq_post or fd_mq_get. Their operation should be quick.2368 * Note that the callbacks are called synchronously, during fd_fifo_post or fd_fifo_get. Their operation should be quick. 2360 2369 * 2361 2370 * RETURN VALUE: … … 2363 2372 * EINVAL : A parameter is invalid. 2364 2373 */ 2365 int fd_ mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue*, void **) );2366 2367 /* 2368 * FUNCTION: fd_ mq_post2369 * 2370 * PARAMETERS: 2371 * queue : The queue in which the messagemust be posted.2372 * msg : The messagethat is put in the queue.2373 * 2374 * DESCRIPTION: 2375 * A message is added in a queue. Messages are retrieved from the queue (in FIFO order)2376 * with the fd_ mq_get, fd_mq_tryget, or fd_mq_timedget functions.2377 * 2378 * RETURN VALUE: 2379 * 0 : The messageis queued.2374 int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) ); 2375 2376 /* 2377 * FUNCTION: fd_fifo_post 2378 * 2379 * PARAMETERS: 2380 * queue : The queue in which the element must be posted. 2381 * item : The element that is put in the queue. 2382 * 2383 * DESCRIPTION: 2384 * An element is added in a queue. Elements are retrieved from the queue in FIFO order 2385 * with the fd_fifo_get, fd_fifo_tryget, or fd_fifo_timedget functions. 2386 * 2387 * RETURN VALUE: 2388 * 0 : The element is queued. 2380 2389 * EINVAL : A parameter is invalid. 2381 2390 * ENOMEM : Not enough memory to complete the operation. 2382 2391 */ 2383 int fd_mq_post ( struct mqueue * queue, struct msg ** msg ); 2384 2385 /* 2386 * FUNCTION: fd_mq_get 2387 * 2388 * PARAMETERS: 2389 * queue : The queue from which the message must be retrieved. 2390 * msg : On return, the first message of the queue is stored here. 2391 * 2392 * DESCRIPTION: 2393 * This function retrieves a message from a queue. If the queue is empty, the function will block the 2394 * thread until a new message is posted to the queue, or until the thread is canceled (in which case the 2392 int fd_fifo_post_int ( struct fifo * queue, void ** item ); 2393 #define fd_fifo_post(queue, item) \ 2394 fd_fifo_post_int((queue), (void *)(item)) 2395 2396 /* 2397 * FUNCTION: fd_fifo_get 2398 * 2399 * PARAMETERS: 2400 * queue : The queue from which the first element must be retrieved. 2401 * item : On return, the first element of the queue is stored here. 2402 * 2403 * DESCRIPTION: 2404 * This function retrieves the first element from a queue. If the queue is empty, the function will block the 2405 * thread until a new element is posted to the queue, or until the thread is canceled (in which case the 2395 2406 * function does not return). 2396 2407 * 2397 2408 * RETURN VALUE: 2398 * 0 : A new message has been retrieved. 2399 * EINVAL : A parameter is invalid. 2400 */ 2401 int fd_mq_get ( struct mqueue * queue, struct msg ** msg ); 2402 2403 /* 2404 * FUNCTION: fd_mq_tryget 2405 * 2406 * PARAMETERS: 2407 * queue : The queue from which the message must be retrieved. 2409 * 0 : A new element has been retrieved. 2410 * EINVAL : A parameter is invalid. 2411 */ 2412 int fd_fifo_get_int ( struct fifo * queue, void ** item ); 2413 #define fd_fifo_get(queue, item) \ 2414 fd_fifo_get_int((queue), (void *)(item)) 2415 2416 /* 2417 * FUNCTION: fd_fifo_tryget 2418 * 2419 * PARAMETERS: 2420 * queue : The queue from which the element must be retrieved. 2408 2421 * msg : On return, the message is stored here. 2409 2422 * 2410 2423 * DESCRIPTION: 2411 * This function is similar to fd_ mq_get, except that it will not block if2424 * This function is similar to fd_fifo_get, except that it will not block if 2412 2425 * the queue is empty, but return EWOULDBLOCK instead. 2413 2426 * 2414 2427 * RETURN VALUE: 2415 * 0 : A new messagehas been retrieved.2428 * 0 : A new element has been retrieved. 2416 2429 * EINVAL : A parameter is invalid. 2417 2430 * EWOULDBLOCK : The queue was empty. 2418 2431 */ 2419 int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg ); 2420 2421 /* 2422 * FUNCTION: fd_mq_timedget 2423 * 2424 * PARAMETERS: 2425 * queue : The queue from which the message must be retrieved. 2426 * msg : On return, the message is stored here. 2427 * abstime : the absolute time until which we allow waiting for a message. 2428 * 2429 * DESCRIPTION: 2430 * This function is similar to fd_mq_get, except that it will block if the queue is empty 2432 int fd_fifo_tryget_int ( struct fifo * queue, void ** item ); 2433 #define fd_fifo_tryget(queue, item) \ 2434 fd_fifo_tryget_int((queue), (void *)(item)) 2435 2436 /* 2437 * FUNCTION: fd_fifo_timedget 2438 * 2439 * PARAMETERS: 2440 * queue : The queue from which the element must be retrieved. 2441 * item : On return, the element is stored here. 2442 * abstime : the absolute time until which we allow waiting for an item. 2443 * 2444 * DESCRIPTION: 2445 * This function is similar to fd_fifo_get, except that it will block if the queue is empty 2431 2446 * only until the absolute time abstime (see pthread_cond_timedwait for + info). 2432 2447 * If the queue is still empty when the time expires, the function returns ETIMEDOUT 2433 2448 * 2434 2449 * RETURN VALUE: 2435 * 0 : A new message has been retrieved. 2436 * EINVAL : A parameter is invalid. 2437 * ETIMEDOUT : The time out has passed and no message has been received. 2438 */ 2439 int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime ); 2450 * 0 : A new item has been retrieved. 2451 * EINVAL : A parameter is invalid. 2452 * ETIMEDOUT : The time out has passed and no item has been received. 2453 */ 2454 int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime ); 2455 #define fd_fifo_timedget(queue, item, abstime) \ 2456 fd_fifo_timedget_int((queue), (void *)(item), (abstime)) 2440 2457 2441 2458 #endif /* _LIBFREEDIAMETER_H */
Note: See TracChangeset
for help on using the changeset viewer.