X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fcommon.h;h=895c5a403494e5ce2ba206cd4663f245cc11cbe6;hb=f1563c45b37bba7d51228af44dc184a9d0308e81;hp=e78d5143b69ff4eace11c8816881f49d7a21d464;hpb=93a5a39800fce1f1ee70edf0968f6a5407682ad2;p=awesomized%2Flibmemcached diff --git a/libmemcached/common.h b/libmemcached/common.h index e78d5143..895c5a40 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -71,6 +71,13 @@ struct memcached_continuum_item_st uint32_t value; }; +/* Yum, Fortran.... can you make the reference? */ +typedef enum { + MEM_NOT= -1, + MEM_FALSE= false, + MEM_TRUE= true, +} memcached_ternary_t; + #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) @@ -83,7 +90,6 @@ struct memcached_continuum_item_st #define unlikely(x) if(__builtin_expect((x) != 0, 0)) #endif - #define MEMCACHED_BLOCK_SIZE 1024 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350 #define SMALL_STRING_LEN 1024 @@ -155,4 +161,42 @@ static inline memcached_return_t memcached_validate_key_length(size_t key_length return MEMCACHED_SUCCESS; } +#ifdef TCP_CORK + #define CORK TCP_CORK +#elif defined TCP_NOPUSH + #define CORK TCP_NOPUSH +#endif + +/* + test_cork() tries to enable TCP_CORK. IF TCP_CORK is not an option + on the system it returns false but sets errno to 0. Otherwise on + failure errno is set. +*/ +static inline memcached_ternary_t test_cork(memcached_server_st *ptr, int enable) +{ +#ifdef CORK + if (ptr->type != MEMCACHED_CONNECTION_TCP) + return MEM_FALSE; + + int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK, + &enable, (socklen_t)sizeof(int)); + if (! err) + { + return MEM_TRUE; + } + + perror(strerror(errno)); + ptr->cached_errno= errno; + + return MEM_FALSE; +#else + (void)ptr; + (void)enable; + + ptr->cached_errno= 0; + + return MEM_NOT; +#endif +} + #endif /* LIBMEMCACHED_COMMON_H */