Permalink
Browse files

renamed push_source and push_destination to push_server and push_client

  • Loading branch information...
1 parent 7f56492 commit 2ee68bbae39ff0b932cc4c66426516be1bac16ca @slact committed Aug 26, 2009
Showing with 58 additions and 58 deletions.
  1. +20 −20 README
  2. +26 −26 src/ngx_http_push_module.c
  3. +12 −12 src/ngx_http_push_module.h
View
40 README
@@ -11,39 +11,39 @@ http {
#for buffering and stuff
push_shm_size 12M; #default is 3M
- #message source server
+ #push_server
server {
listen localhost:8089;
location / {
default_type text/plain;
set $push_id $arg_id; #/?id=239aff3 or somesuch
- push_source;
+ push_server;
push_buffer_timeout 2h; #buffered messages expire after 2 hours
}
}
- #long-polling client server
+ #long-polling client
server {
listen 8088;
location / {
default_type text/plain;
set $push_id $arg_id; #/?id=239aff3 or somesuch
- push_destination;
+ push_client;
}
}
}
-- Configuration options & variables --
Options:
-push_source (no arguments, server or location config)
-defines a server or location as the push_source, described below.
+push_server (no arguments, server or location config)
+defines a server or location as the push_server, described below.
-push_destination (no arguments, in server or location config)
-defines a push_destination server or location
+push_client (no arguments, in server or location config)
+defines a push_client server or location
push_queue_messages (on|off (default to on), anywhere)
Whether or not message queuing is enabled. If set to off,
-messages will be delivered only if a destination connection is already
+messages will be delivered only if a push_client connection is already
present for the id.
push_message_timeout (time (default to 1h), anywhere)
@@ -56,7 +56,7 @@ buffering.
Variables:
$push_id
-The id associated with a push_source or push_destination.
+The id associated with a push_server or push_client.
set $push_id $arg_id would set $push_id to the url parameter "id"
------------ Operation ----------------
@@ -65,18 +65,18 @@ Clients will connect to http://example.com:8088/?id=... and have the
response delayed until a message is POSTed to http://localhost:8089/?id=...
Messages can be sent to clients that have not yet connected, i.e. they are queued.
-Upon sending a request to a push_source location, the server will respond with
+Upon sending a request to a push_server location, the server will respond with
a 201 Created if the message has been sent. If it must be queued up (i.e. the
-destination id is presently connected), a 202 Accepted will be sent.
+push_client id is presently connected), a 202 Accepted will be sent.
-It's a damn good idea to make sure the push_source location is not visible
+It's a damn good idea to make sure the push_server location is not visible
publically, as it is intended for use only by your application.
--------- "Protocol" spec -------------
-Let push_source refer to a location (or server) configured with the push_source; option.
-Let push_destination refer to a location (or server) configured with the push_destination; option.
+Let push_server refer to a location (or server) configured with the push_server; option.
+Let push_client refer to a location (or server) configured with the push_client; option.
-at push_destination:
+at push_client:
Only POST requests are allowed to this location. The response will be delayed until a message
for the $push_id of said requests becomes available, at which point its contents will be sent
in the body of the response with a 200 OK status code.
@@ -85,7 +85,7 @@ at push_destination:
newer of the two. The older request receives an immediate response with a 409 Conflict status
code.
-at push_source:
+at push_server:
POST, PUT, and DELETE requests are allowed at this location.
A POST request will have its body ("the message"), sent to the request identified by
$push_id, with the Content-Type header forwarded. If no such request exists, the message
@@ -99,16 +99,16 @@ at push_source:
the message will be lost, and the server will return a 200 OK status code.
(NOT IMPLEMENTED YET) a DELETE deletes all messages intended for $push_id. If there is a waiting
- request on push_destination identified by $push_id, it will be immediately responded to with a
+ request on push_client identified by $push_id, it will be immediately responded to with a
204 No Content status code.
-----------------------------
TODO:
- - Implelent DELETE for push_source.
+ - Implelent DELETE for push_server.
- Add a push_accomodate_strangers setting (presently defaulting to on). When set to off, requests
with a previously-unseen $push_id will be rejected.
- - When POSTing to push_source, if Content-Type is "message/http", the response sent to $push_id
+ - When POSTing to push_server, if Content-Type is "message/http", the response sent to $push_id
should be created from the body of the request.
View
@@ -58,13 +58,13 @@ static ngx_int_t ngx_http_push_set_id(ngx_str_t *id, ngx_http_request_t *r, ngx_
} \
}
-#define ngx_http_push_remove_destination_request_locked(node) \
+#define ngx_http_push_remove_client_request_locked(node) \
(node)->request = NULL; \
if((node)->cleanup!=NULL) { \
(node)->cleanup->node=NULL; \
}
-static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t *r) {
+static ngx_int_t ngx_http_push_client_handler(ngx_http_request_t *r) {
ngx_http_push_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_module);
ngx_slab_pool_t *shpool = (ngx_slab_pool_t *) ngx_http_push_shm_zone->shm.addr;
ngx_str_t id;
@@ -91,7 +91,7 @@ static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t *r) {
if (node->request!=NULL) { //oh shit, someone's already waiting for a message on this id.
ngx_shmtx_lock(&shpool->mutex);
existing_request = node->request;
- ngx_http_push_remove_destination_request_locked(node);
+ ngx_http_push_remove_client_request_locked(node);
ngx_shmtx_unlock(&shpool->mutex);
ngx_http_finalize_request(existing_request, NGX_HTTP_CONFLICT); //bump the old request.
}
@@ -108,17 +108,17 @@ static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t *r) {
r->read_event_handler = ngx_http_test_reading; //definitely test to see if the connection got closed or something.
//attach a cleaner to remove the request from the node, if need be
- ngx_pool_cleanup_t *cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_push_destination_cleanup_t));
+ ngx_pool_cleanup_t *cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_push_client_cleanup_t));
if (cln == NULL) { //make sure we can.
return NGX_ERROR;
}
ngx_shmtx_lock(&shpool->mutex);
- node->cleanup = ((ngx_http_push_destination_cleanup_t *) cln->data);
+ node->cleanup = ((ngx_http_push_client_cleanup_t *) cln->data);
ngx_shmtx_unlock(&shpool->mutex);
- cln->handler = (ngx_pool_cleanup_pt) ngx_http_push_destination_cleanup;
- ((ngx_http_push_destination_cleanup_t *) cln->data)->node = node;
- ((ngx_http_push_destination_cleanup_t *) cln->data)->request = r;
- ((ngx_http_push_destination_cleanup_t *) cln->data)->shpool = shpool;
+ cln->handler = (ngx_pool_cleanup_pt) ngx_http_push_client_cleanup;
+ ((ngx_http_push_client_cleanup_t *) cln->data)->node = node;
+ ((ngx_http_push_client_cleanup_t *) cln->data)->request = r;
+ ((ngx_http_push_client_cleanup_t *) cln->data)->shpool = shpool;
return NGX_DONE; //and wait.
}
@@ -157,7 +157,7 @@ static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t *r) {
ngx_shmtx_lock(&shpool->mutex);
}
- rc = ngx_http_push_set_destination_header(r, &msg->content_type); //content type is copied
+ rc = ngx_http_push_set_client_header(r, &msg->content_type); //content type is copied
out = ngx_http_push_create_output_chain(r, msg->buf); //buffer is copied
out->buf->file=file;
//we no longer need the message and can free its shm slab.
@@ -172,11 +172,11 @@ static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t *r) {
return rc;
}
- return ngx_http_push_set_destination_body(r, out);
+ return ngx_http_push_set_client_body(r, out);
}
}
-static void ngx_http_push_source_body_handler(ngx_http_request_t * r) {
+static void ngx_http_push_server_body_handler(ngx_http_request_t * r) {
ngx_str_t id;
ngx_http_push_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_module);
ngx_slab_pool_t *shpool = (ngx_slab_pool_t *) ngx_http_push_shm_zone->shm.addr;
@@ -289,14 +289,14 @@ static void ngx_http_push_source_body_handler(ngx_http_request_t * r) {
time_t timeout = cf->buffer_timeout;
msg->expires= timeout==0 ? 0 : (ngx_time() + timeout);
ngx_shmtx_unlock(&shpool->mutex);
- //okay, done storing. now respond to the source request
+ //okay, done storing. now respond to the server request
r->headers_out.status=NGX_HTTP_OK;
r->headers_out.status_line.len =sizeof("202 Accepted")- 1;
r->headers_out.status_line.data=(u_char *) "202 Accepted";
}
else if(r_client!=NULL) {
ngx_int_t rc;
- rc = ngx_http_push_set_destination_header(r_client, (content_type_len>0 ? &r->headers_in.content_type->value : NULL));
+ rc = ngx_http_push_set_client_header(r_client, (content_type_len>0 ? &r->headers_in.content_type->value : NULL));
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
ngx_http_finalize_request(r_client, rc);
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -310,14 +310,14 @@ static void ngx_http_push_source_body_handler(ngx_http_request_t * r) {
}
if(buf->in_file && buf->file->fd!=NGX_INVALID_FILE){
- //delete file when the push_source request finishes
+ //delete file when the push_server request finishes
ngx_http_push_add_pool_cleaner_delete_file(r->pool, buf->file);
}
ngx_shmtx_lock(&shpool->mutex);
- //we don't want the destination request cleanup to accidentally access an already freed node on cleanup
- ngx_http_push_remove_destination_request_locked(node);
+ //we don't want the client request cleanup to accidentally access an already freed node on cleanup
+ ngx_http_push_remove_client_request_locked(node);
ngx_shmtx_unlock(&shpool->mutex);
- ngx_http_finalize_request(r_client, ngx_http_push_set_destination_body(r_client, ngx_http_push_create_output_chain(r_client, buf)));
+ ngx_http_finalize_request(r_client, ngx_http_push_set_client_body(r_client, ngx_http_push_create_output_chain(r_client, buf)));
r->headers_out.status=NGX_HTTP_OK;
r->headers_out.status_line.len =sizeof("201 Created")- 1;
@@ -338,12 +338,12 @@ static void ngx_http_push_source_body_handler(ngx_http_request_t * r) {
ngx_slab_free_locked(shpool, msg);
};
r_client = node->request;
- ngx_http_push_remove_destination_request_locked(node);
+ ngx_http_push_remove_client_request_locked(node);
ngx_http_push_delete_node((ngx_rbtree_t *) ngx_http_push_shm_zone->data, (ngx_rbtree_node_t *) node, shpool);
ngx_shmtx_unlock(&shpool->mutex);
if(r_client!=NULL) {
- //respond to the destination request with a 410
+ //respond to the client request with a 410
r_client->headers_out.status=NGX_HTTP_NOT_FOUND;
r_client->headers_out.status_line.len =sizeof("410 Gone")- 1;
r_client->headers_out.status_line.data=(u_char *) "410 Gone";
@@ -397,10 +397,10 @@ static ngx_int_t ngx_http_push_node_info(ngx_http_request_t *r, ngx_uint_t queue
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- return ngx_http_push_set_destination_body(r, ngx_http_push_create_output_chain(r, b));
+ return ngx_http_push_set_client_body(r, ngx_http_push_create_output_chain(r, b));
}
-static ngx_int_t ngx_http_push_source_handler(ngx_http_request_t * r) {
+static ngx_int_t ngx_http_push_server_handler(ngx_http_request_t * r) {
ngx_int_t rc;
/* Instruct ngx_http_read_client_request_body to store the request
@@ -410,14 +410,14 @@ static ngx_int_t ngx_http_push_source_handler(ngx_http_request_t * r) {
r->request_body_in_clean_file = 0;
r->request_body_file_log_level = 0;
- rc = ngx_http_read_client_request_body(r, ngx_http_push_source_body_handler);
+ rc = ngx_http_read_client_request_body(r, ngx_http_push_server_body_handler);
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}
return NGX_DONE;
}
-static ngx_int_t ngx_http_push_set_destination_header(ngx_http_request_t *r, ngx_str_t *content_type) {
+static ngx_int_t ngx_http_push_set_client_header(ngx_http_request_t *r, ngx_str_t *content_type) {
//content-type is _copied_
if (content_type!=NULL && content_type->data!=NULL && content_type->len > 0) {
r->headers_out.content_type.len=content_type->len;
@@ -447,15 +447,15 @@ static ngx_chain_t * ngx_http_push_create_output_chain(ngx_http_request_t *r, ng
return out;
}
-static ngx_int_t ngx_http_push_set_destination_body(ngx_http_request_t *r, ngx_chain_t *out)
+static ngx_int_t ngx_http_push_set_client_body(ngx_http_request_t *r, ngx_chain_t *out)
{
if (out==NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
return ngx_http_output_filter(r, out);
}
-static void ngx_http_push_destination_cleanup(ngx_http_push_destination_cleanup_t *data) {
+static void ngx_http_push_client_cleanup(ngx_http_push_client_cleanup_t *data) {
if(data->node!=NULL) {
ngx_shmtx_lock(&data->shpool->mutex);
if(data->node->request == data->request) {
View
@@ -31,7 +31,7 @@ typedef struct {
ngx_http_request_t *request;
ngx_http_push_node_t *node;
ngx_slab_pool_t *shpool;
-} ngx_http_push_destination_cleanup_t;
+} ngx_http_push_client_cleanup_t;
//our typecast-friendly rbtree node
struct ngx_http_push_node_s {
@@ -41,26 +41,26 @@ struct ngx_http_push_node_s {
ngx_uint_t message_queue_len;
ngx_http_request_t *request;
time_t last_seen;
- ngx_http_push_destination_cleanup_t *cleanup;
+ ngx_http_push_client_cleanup_t *cleanup;
};
-//source stuff
-static char * ngx_http_push_source(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); //push_source hook
-static ngx_int_t ngx_http_push_source_handler(ngx_http_request_t * r);
-static void ngx_http_push_source_body_handler(ngx_http_request_t * r);
+//server stuff
+static char * ngx_http_push_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); //push_server hook
+static ngx_int_t ngx_http_push_server_handler(ngx_http_request_t * r);
+static void ngx_http_push_server_body_handler(ngx_http_request_t * r);
static ngx_int_t ngx_http_push_node_info(ngx_http_request_t *r, ngx_uint_t queue_len, time_t last_seen);
-//destination stuff
-static char * ngx_http_push_destination(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); //push_destination hook
-static ngx_int_t ngx_http_push_destination_handler(ngx_http_request_t * r);
+//client stuff
+static char * ngx_http_push_client(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); //push_client hook
+static ngx_int_t ngx_http_push_client_handler(ngx_http_request_t * r);
-static ngx_int_t ngx_http_push_set_destination_header(ngx_http_request_t *r, ngx_str_t *content_type);
+static ngx_int_t ngx_http_push_set_client_header(ngx_http_request_t *r, ngx_str_t *content_type);
static ngx_chain_t* ngx_http_push_create_output_chain(ngx_http_request_t *r, ngx_buf_t *buf);
-static ngx_int_t ngx_http_push_set_destination_body(ngx_http_request_t *r, ngx_chain_t *out);
+static ngx_int_t ngx_http_push_set_client_body(ngx_http_request_t *r, ngx_chain_t *out);
static ngx_int_t ngx_http_push_add_pool_cleaner_delete_file(ngx_pool_t *pool, ngx_file_t *file);
-static void ngx_http_push_destination_cleanup(ngx_http_push_destination_cleanup_t * data); //request pool cleaner
+static void ngx_http_push_client_cleanup(ngx_http_push_client_cleanup_t * data); //request pool cleaner
//misc stuff
ngx_shm_zone_t * ngx_http_push_shm_zone = NULL;

0 comments on commit 2ee68bb

Please sign in to comment.