Example #1
0
int
memcached_tuple_set(struct memcached_connection *con,
		    const char *kpos, uint32_t klen, uint64_t expire,
		    const char *vpos, uint32_t vlen, uint64_t cas,
		    uint32_t flags)
{
	(void )con;
	uint64_t time = fiber_time64();
	uint32_t len = mp_sizeof_array(6)      +
		       mp_sizeof_str  (klen)   +
		       mp_sizeof_uint (expire) +
		       mp_sizeof_uint (time)   +
		       mp_sizeof_str  (vlen)   +
		       mp_sizeof_uint (cas)    +
		       mp_sizeof_uint (flags);
	char *begin  = (char *)box_txn_alloc(len);
	if (begin == NULL) {
		memcached_error_ENOMEM(len, "tuple");
		return -1;
	}
	char *end = mp_encode_array(begin, 6);
	      end = mp_encode_str  (end, kpos, klen);
	      end = mp_encode_uint (end, expire);
	      end = mp_encode_uint (end, time);
	      end = mp_encode_str  (end, vpos, vlen);
	      end = mp_encode_uint (end, cas);
	      end = mp_encode_uint (end, flags);
	assert(end <= begin + len);
	return box_replace(con->cfg->space_id, begin, end, NULL);
}
Example #2
0
uint64_t
convert_exptime (uint64_t exptime)
{
	if (exptime == 0) return INF_EXPTIME; /* 0 means never expire */
	if (exptime <= MAX_EXPTIME)
		exptime = fiber_time64() + exptime * 1000000;
	else
		exptime = exptime * 1000000;
	return exptime;
}
Example #3
0
static inline int
is_expired (uint64_t exptime, uint64_t time, uint64_t flush)
{
	(void )time;
	uint64_t curtime = fiber_time64();
	/* Expired by TTL or FLUSH */
	if (exptime <= curtime || (flush <= curtime && time <= flush))
		return 1;
	return 0;
}
Example #4
0
static
int
mosq_poll_one_ctx(mosq_t *ctx, int revents, size_t timeout, int max_packets)
{
	/** XXX
	 * I'm confused: socket < 0 means MOSQ_ERR_NO_CONN
	 */
	int rc = MOSQ_ERR_NO_CONN;

	int fd = mosquitto_socket(ctx->mosq);

	if (fd >= 0) {

		/** Wait until event
		 */
		revents = coio_wait(fd, revents, timeout);

		if (revents != 0) {
			if (revents & COIO_READ)
				rc = mosquitto_loop_read(ctx->mosq, max_packets);
			if (revents & COIO_WRITE)
				rc = mosquitto_loop_write(ctx->mosq, max_packets);
		}

		/**
		 * mosquitto_loop_miss
		 * This function deals with handling PINGs and checking
		 * whether messages need to be retried,
		 * so should be called fairly _frequently_(!).
		 * */
		if (ctx->next_misc_timeout < fiber_time64()) {
			rc = mosquitto_loop_misc(ctx->mosq);
			ctx->next_misc_timeout = fiber_time64() + 1200;
		}
	}

    return rc;
}