コード例 #1
0
ファイル: pgsql_cb.c プロジェクト: jorisvink/kore
void
db_state_change(struct kore_pgsql *pgsql, void *arg)
{
	struct connection	*c = arg;

	printf("%p: state change on pgsql %d\n", arg, pgsql->state);

	switch (pgsql->state) {
	case KORE_PGSQL_STATE_INIT:
		db_init(c, pgsql);
		break;
	case KORE_PGSQL_STATE_WAIT:
		break;
	case KORE_PGSQL_STATE_COMPLETE:
		kore_connection_disconnect(c);
		break;
	case KORE_PGSQL_STATE_ERROR:
		kore_pgsql_logerror(pgsql);
		kore_connection_disconnect(c);
		break;
	case KORE_PGSQL_STATE_RESULT:
		db_results(pgsql, c);
		break;
	default:
		kore_pgsql_continue(pgsql);
		break;
	}
}
コード例 #2
0
ファイル: pgsql.c プロジェクト: ebottabi/kore
/*
 * After firing off the query, we returned HTTP_STATE_RETRY (see above).
 * When request_db_wait() finally is called by Kore we will have results
 * from pgsql so we'll process them.
 */
int
request_db_wait(struct http_request *req)
{
	struct rstate	*state = req->hdlr_extra;

	kore_log(LOG_NOTICE, "request_db_wait: %d", state->sql.state);

	/*
	 * When we get here, our asynchronous pgsql query has
	 * given us something, check the state to figure out what.
	 */
	switch (state->sql.state) {
	case KORE_PGSQL_STATE_WAIT:
		return (HTTP_STATUS_RETRY);
	case KORE_PGSQL_STATE_COMPLETE:
		req->fsm_state = REQ_STATE_DONE;
		break;
	case KORE_PGSQL_STATE_ERROR:
		req->fsm_state = REQ_STATE_ERROR;
		kore_pgsql_logerror(&state->sql);
		break;
	case KORE_PGSQL_STATE_RESULT:
		req->fsm_state = REQ_STATE_DB_READ;
		break;
	default:
		/* This MUST be present in order to advance the pgsql state */
		kore_pgsql_continue(req, &state->sql);
		break;
	}

	return (HTTP_STATE_CONTINUE);
}
コード例 #3
0
ファイル: pgsql_cb.c プロジェクト: jorisvink/kore
void
db_init(struct connection *c, struct kore_pgsql *pgsql)
{
	if (!kore_pgsql_setup(pgsql, "db", KORE_PGSQL_ASYNC)) {
		if (pgsql->state == KORE_PGSQL_STATE_INIT) {
			printf("\twaiting for available pgsql connection\n");
			return;
		}

		kore_pgsql_logerror(pgsql);
		kore_connection_disconnect(c);
		return;
	}

	printf("\tgot pgsql connection\n");
	if (!kore_pgsql_query(pgsql, "SELECT * FROM coders, pg_sleep(5)")) {
		kore_pgsql_logerror(pgsql);
		kore_connection_disconnect(c);
		return;
	}
	printf("\tquery fired off!\n");
}