int cmd_delete(int argc, char** argv, yrmcds* s) { if( argc != 1 ) { fprintf(stderr, "Wrong number of arguments.\n"); return 1; } yrmcds_response r[1]; uint32_t serial; yrmcds_error e = yrmcds_remove(s, argv[0], strlen(argv[0]), quiet, &serial); CHECK_ERROR(e); if( quiet ) { e = yrmcds_noop(s, &serial); CHECK_ERROR(e); } if( debug ) fprintf(stderr, "request serial = %u\n", serial); while( 1 ) { e = yrmcds_recv(s, r); CHECK_ERROR(e); if( debug ) print_response(r); CHECK_RESPONSE(r); if( r->serial == serial ) break; } write_data(r); return 0; }
static void *writer_main(void *_conn) { struct st_h2o_memcached_conn_t *conn = _conn; yrmcds_error err; pthread_mutex_lock(&conn->ctx->mutex); while (!__sync_add_and_fetch(&conn->writer_exit_requested, 0)) { while (!h2o_linklist_is_empty(&conn->ctx->pending)) { h2o_memcached_req_t *req = H2O_STRUCT_FROM_MEMBER(h2o_memcached_req_t, pending, conn->ctx->pending.next); h2o_linklist_unlink(&req->pending); pthread_mutex_unlock(&conn->ctx->mutex); switch (req->type) { case REQ_TYPE_GET: pthread_mutex_lock(&conn->mutex); h2o_linklist_insert(&conn->inflight, &req->inflight); pthread_mutex_unlock(&conn->mutex); if ((err = yrmcds_get(&conn->yrmcds, req->key.base, req->key.len, 0, &req->data.get.serial)) != YRMCDS_OK) goto Error; break; case REQ_TYPE_SET: err = yrmcds_set(&conn->yrmcds, req->key.base, req->key.len, req->data.set.value.base, req->data.set.value.len, 0, req->data.set.expiration, 0, !conn->yrmcds.text_mode, NULL); discard_req(req); if (err != YRMCDS_OK) goto Error; break; case REQ_TYPE_DELETE: err = yrmcds_remove(&conn->yrmcds, req->key.base, req->key.len, !conn->yrmcds.text_mode, NULL); discard_req(req); if (err != YRMCDS_OK) goto Error; break; default: fprintf(stderr, "[lib/common/memcached.c] unknown type:%d\n", (int)req->type); err = YRMCDS_NOT_IMPLEMENTED; goto Error; } pthread_mutex_lock(&conn->ctx->mutex); } pthread_cond_wait(&conn->ctx->cond, &conn->ctx->mutex); } pthread_mutex_unlock(&conn->ctx->mutex); return NULL; Error: fprintf(stderr, "[lib/common/memcached.c] failed to send request; %s\n", yrmcds_strerror(err)); /* doc says the call can be used to interrupt yrmcds_recv */ yrmcds_shutdown(&conn->yrmcds); return NULL; }