Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
a61b7a0c
Commit
a61b7a0c
authored
Nov 12, 2014
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce number of calls to ngx_http_push_stream_find_channel function
parent
9935347c
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
114 deletions
+66
-114
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+1
-0
ngx_http_push_stream_module_utils.h
include/ngx_http_push_stream_module_utils.h
+2
-2
ngx_http_push_stream_module.c
src/ngx_http_push_stream_module.c
+6
-9
ngx_http_push_stream_module_publisher.c
src/ngx_http_push_stream_module_publisher.c
+10
-8
ngx_http_push_stream_module_subscriber.c
src/ngx_http_push_stream_module_subscriber.c
+27
-65
ngx_http_push_stream_module_utils.c
src/ngx_http_push_stream_module_utils.c
+12
-25
ngx_http_push_stream_module_websocket.c
src/ngx_http_push_stream_module_websocket.c
+1
-1
ngx_http_push_stream_rbtree_util.c
src/ngx_http_push_stream_rbtree_util.c
+7
-4
No files found.
include/ngx_http_push_stream_module.h
View file @
a61b7a0c
...
@@ -178,6 +178,7 @@ typedef struct {
...
@@ -178,6 +178,7 @@ typedef struct {
ngx_queue_t
queue
;
ngx_queue_t
queue
;
ngx_str_t
*
id
;
ngx_str_t
*
id
;
ngx_uint_t
backtrack_messages
;
ngx_uint_t
backtrack_messages
;
ngx_http_push_stream_channel_t
*
channel
;
}
ngx_http_push_stream_requested_channel_t
;
}
ngx_http_push_stream_requested_channel_t
;
typedef
struct
{
typedef
struct
{
...
...
include/ngx_http_push_stream_module_utils.h
View file @
a61b7a0c
...
@@ -253,7 +253,7 @@ static void ngx_http_push_stream_unescape_uri(ngx_str_t *value);
...
@@ -253,7 +253,7 @@ static void ngx_http_push_stream_unescape_uri(ngx_str_t *value);
static
void
ngx_http_push_stream_complex_value
(
ngx_http_request_t
*
r
,
ngx_http_complex_value_t
*
val
,
ngx_str_t
*
value
);
static
void
ngx_http_push_stream_complex_value
(
ngx_http_request_t
*
r
,
ngx_http_complex_value_t
*
val
,
ngx_str_t
*
value
);
ngx_
http_push_stream_channel_t
*
ngx_http_push_stream_add_msg_to_channel
(
ngx_http_request_t
*
r
,
ngx_str_t
*
id
,
u_char
*
text
,
size_t
len
,
ngx_str_t
*
event_id
,
ngx_str_t
*
event_type
,
ngx_pool_t
*
temp_pool
);
ngx_
int_t
ngx_http_push_stream_add_msg_to_channel
(
ngx_http_request_t
*
r
,
ngx_http_push_stream_channel_t
*
channel
,
u_char
*
text
,
size_t
len
,
ngx_str_t
*
event_id
,
ngx_str_t
*
event_type
,
ngx_pool_t
*
temp_pool
);
static
void
ngx_http_push_stream_ping_timer_wake_handler
(
ngx_event_t
*
ev
);
static
void
ngx_http_push_stream_ping_timer_wake_handler
(
ngx_event_t
*
ev
);
static
void
ngx_http_push_stream_disconnect_timer_wake_handler
(
ngx_event_t
*
ev
);
static
void
ngx_http_push_stream_disconnect_timer_wake_handler
(
ngx_event_t
*
ev
);
...
@@ -270,7 +270,7 @@ static void ngx_http_push_stream_worker_subscriber_cleanup_locke
...
@@ -270,7 +270,7 @@ static void ngx_http_push_stream_worker_subscriber_cleanup_locke
static
ngx_str_t
*
ngx_http_push_stream_create_str
(
ngx_pool_t
*
pool
,
uint
len
);
static
ngx_str_t
*
ngx_http_push_stream_create_str
(
ngx_pool_t
*
pool
,
uint
len
);
static
void
ngx_http_push_stream_mark_message_to_delete_locked
(
ngx_http_push_stream_msg_t
*
msg
,
ngx_http_push_stream_shm_data_t
*
data
);
static
void
ngx_http_push_stream_mark_message_to_delete_locked
(
ngx_http_push_stream_msg_t
*
msg
,
ngx_http_push_stream_shm_data_t
*
data
);
static
ngx_flag_t
ngx_http_push_stream_delete_channel
(
ngx_http_push_stream_main_conf_t
*
mcf
,
ngx_
str_t
*
id
,
u_char
*
text
,
size_t
len
,
ngx_pool_t
*
temp_pool
);
static
ngx_flag_t
ngx_http_push_stream_delete_channel
(
ngx_http_push_stream_main_conf_t
*
mcf
,
ngx_
http_push_stream_channel_t
*
channel
,
u_char
*
text
,
size_t
len
,
ngx_pool_t
*
temp_pool
);
static
void
ngx_http_push_stream_collect_expired_messages_data
(
ngx_http_push_stream_shm_data_t
*
data
,
ngx_flag_t
force
);
static
void
ngx_http_push_stream_collect_expired_messages_data
(
ngx_http_push_stream_shm_data_t
*
data
,
ngx_flag_t
force
);
static
void
ngx_http_push_stream_collect_expired_messages_and_empty_channels
(
ngx_flag_t
force
);
static
void
ngx_http_push_stream_collect_expired_messages_and_empty_channels
(
ngx_flag_t
force
);
static
void
ngx_http_push_stream_free_message_memory_locked
(
ngx_slab_pool_t
*
shpool
,
ngx_http_push_stream_msg_t
*
msg
);
static
void
ngx_http_push_stream_free_message_memory_locked
(
ngx_slab_pool_t
*
shpool
,
ngx_http_push_stream_msg_t
*
msg
);
...
...
src/ngx_http_push_stream_module.c
View file @
a61b7a0c
...
@@ -239,7 +239,6 @@ ngx_http_push_stream_send_response_channels_info_detailed(ngx_http_request_t *r,
...
@@ -239,7 +239,6 @@ ngx_http_push_stream_send_response_channels_info_detailed(ngx_http_request_t *r,
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_http_push_stream_content_subtype_t
*
subtype
=
ngx_http_push_stream_match_channel_info_format_and_content_type
(
r
,
1
);
ngx_http_push_stream_content_subtype_t
*
subtype
=
ngx_http_push_stream_match_channel_info_format_and_content_type
(
r
,
1
);
ngx_http_push_stream_channel_info_t
*
channel_info
;
ngx_http_push_stream_channel_info_t
*
channel_info
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
ngx_http_push_stream_requested_channel_t
*
requested_channel
;
ngx_http_push_stream_requested_channel_t
*
requested_channel
;
ngx_queue_t
*
q
;
ngx_queue_t
*
q
;
ngx_uint_t
qtd_channels
=
0
;
ngx_uint_t
qtd_channels
=
0
;
...
@@ -250,14 +249,12 @@ ngx_http_push_stream_send_response_channels_info_detailed(ngx_http_request_t *r,
...
@@ -250,14 +249,12 @@ ngx_http_push_stream_send_response_channels_info_detailed(ngx_http_request_t *r,
for
(
q
=
ngx_queue_head
(
&
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
for
(
q
=
ngx_queue_head
(
&
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
// search for a existing channel with this id
if
((
requested_channel
->
channel
!=
NULL
)
&&
((
channel_info
=
ngx_pcalloc
(
r
->
pool
,
sizeof
(
ngx_http_push_stream_channel_info_t
)))
!=
NULL
))
{
channel
=
ngx_http_push_stream_find_channel
(
requested_channel
->
id
,
r
->
connection
->
log
,
mcf
);
channel_info
->
id
.
data
=
requested_channel
->
channel
->
id
.
data
;
if
((
channel
!=
NULL
)
&&
((
channel_info
=
ngx_pcalloc
(
r
->
pool
,
sizeof
(
ngx_http_push_stream_channel_info_t
)))
!=
NULL
))
{
channel_info
->
id
.
len
=
requested_channel
->
channel
->
id
.
len
;
channel_info
->
id
.
data
=
channel
->
id
.
data
;
channel_info
->
published_messages
=
requested_channel
->
channel
->
last_message_id
;
channel_info
->
id
.
len
=
channel
->
id
.
len
;
channel_info
->
stored_messages
=
requested_channel
->
channel
->
stored_messages
;
channel_info
->
published_messages
=
channel
->
last_message_id
;
channel_info
->
subscribers
=
requested_channel
->
channel
->
subscribers
;
channel_info
->
stored_messages
=
channel
->
stored_messages
;
channel_info
->
subscribers
=
channel
->
subscribers
;
ngx_queue_insert_tail
(
&
queue_channel_info
,
&
channel_info
->
queue
);
ngx_queue_insert_tail
(
&
queue_channel_info
,
&
channel_info
->
queue
);
qtd_channels
++
;
qtd_channels
++
;
...
...
src/ngx_http_push_stream_module_publisher.c
View file @
a61b7a0c
...
@@ -31,7 +31,6 @@ static ngx_int_t ngx_http_push_stream_publisher_handle_after_read_body(ngx_ht
...
@@ -31,7 +31,6 @@ static ngx_int_t ngx_http_push_stream_publisher_handle_after_read_body(ngx_ht
static
ngx_int_t
static
ngx_int_t
ngx_http_push_stream_publisher_handler
(
ngx_http_request_t
*
r
)
ngx_http_push_stream_publisher_handler
(
ngx_http_request_t
*
r
)
{
{
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
ngx_http_push_stream_main_conf_t
*
mcf
=
ngx_http_get_module_main_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_main_conf_t
*
mcf
=
ngx_http_get_module_main_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_module_ctx_t
*
ctx
;
ngx_http_push_stream_module_ctx_t
*
ctx
;
...
@@ -98,16 +97,19 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
...
@@ -98,16 +97,19 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
if
(
r
->
method
&
(
NGX_HTTP_POST
|
NGX_HTTP_PUT
))
{
if
(
r
->
method
&
(
NGX_HTTP_POST
|
NGX_HTTP_PUT
))
{
// create the channel if doesn't exist
// create the channel if doesn't exist
channel
=
ngx_http_push_stream_get_channel
(
requested_channel
->
id
,
r
->
connection
->
log
,
cf
,
mcf
);
requested_channel
->
channel
=
ngx_http_push_stream_get_channel
(
requested_channel
->
id
,
r
->
connection
->
log
,
cf
,
mcf
);
if
(
channel
==
NULL
)
{
if
(
requested_channel
->
channel
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: unable to allocate memory for new channel"
);
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: unable to allocate memory for new channel"
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
,
NULL
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
,
NULL
);
}
}
if
(
channel
==
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED
)
{
if
(
requested_channel
->
channel
==
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED
)
{
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: number of channels were exceeded"
);
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: number of channels were exceeded"
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED_MESSAGE
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED_MESSAGE
);
}
}
}
else
{
requested_channel
->
channel
=
ngx_http_push_stream_find_channel
(
requested_channel
->
id
,
r
->
connection
->
log
,
mcf
);
}
}
}
}
...
@@ -216,7 +218,7 @@ ngx_http_push_stream_publisher_delete_handler(ngx_http_request_t *r)
...
@@ -216,7 +218,7 @@ ngx_http_push_stream_publisher_delete_handler(ngx_http_request_t *r)
for
(
q
=
ngx_queue_head
(
&
ctx
->
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
for
(
q
=
ngx_queue_head
(
&
ctx
->
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
if
(
ngx_http_push_stream_delete_channel
(
mcf
,
requested_channel
->
id
,
text
,
len
,
r
->
pool
))
{
if
(
ngx_http_push_stream_delete_channel
(
mcf
,
requested_channel
->
channel
,
text
,
len
,
r
->
pool
))
{
qtd_channels
++
;
qtd_channels
++
;
}
}
}
}
...
@@ -235,7 +237,6 @@ ngx_http_push_stream_publisher_body_handler(ngx_http_request_t *r)
...
@@ -235,7 +237,6 @@ ngx_http_push_stream_publisher_body_handler(ngx_http_request_t *r)
ngx_http_push_stream_module_ctx_t
*
ctx
=
ngx_http_get_module_ctx
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_module_ctx_t
*
ctx
=
ngx_http_get_module_ctx
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_buf_t
*
buf
=
NULL
;
ngx_buf_t
*
buf
=
NULL
;
ngx_http_push_stream_channel_t
*
channel
;
ngx_http_push_stream_requested_channel_t
*
requested_channel
;
ngx_http_push_stream_requested_channel_t
*
requested_channel
;
ngx_queue_t
*
q
;
ngx_queue_t
*
q
;
...
@@ -261,8 +262,7 @@ ngx_http_push_stream_publisher_body_handler(ngx_http_request_t *r)
...
@@ -261,8 +262,7 @@ ngx_http_push_stream_publisher_body_handler(ngx_http_request_t *r)
for
(
q
=
ngx_queue_head
(
&
ctx
->
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
for
(
q
=
ngx_queue_head
(
&
ctx
->
requested_channels
->
queue
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
requested_channels
->
queue
);
q
=
ngx_queue_next
(
q
))
{
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
requested_channel
=
ngx_queue_data
(
q
,
ngx_http_push_stream_requested_channel_t
,
queue
);
channel
=
ngx_http_push_stream_add_msg_to_channel
(
r
,
requested_channel
->
id
,
buf
->
pos
,
ngx_buf_size
(
buf
),
event_id
,
event_type
,
r
->
pool
);
if
(
ngx_http_push_stream_add_msg_to_channel
(
r
,
requested_channel
->
channel
,
buf
->
pos
,
ngx_buf_size
(
buf
),
event_id
,
event_type
,
r
->
pool
)
!=
NGX_OK
)
{
if
(
channel
==
NULL
)
{
ngx_http_finalize_request
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
);
ngx_http_finalize_request
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
);
return
;
return
;
}
}
...
@@ -328,6 +328,8 @@ ngx_http_push_stream_channels_statistics_handler(ngx_http_request_t *r)
...
@@ -328,6 +328,8 @@ ngx_http_push_stream_channels_statistics_handler(ngx_http_request_t *r)
if
(
ngx_memn2cmp
(
requested_channel
->
id
->
data
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
data
,
requested_channel
->
id
->
len
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
len
)
==
0
)
{
if
(
ngx_memn2cmp
(
requested_channel
->
id
->
data
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
data
,
requested_channel
->
id
->
len
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
len
)
==
0
)
{
return
ngx_http_push_stream_send_response_all_channels_info_detailed
(
r
,
NULL
);
return
ngx_http_push_stream_send_response_all_channels_info_detailed
(
r
,
NULL
);
}
}
requested_channel
->
channel
=
ngx_http_push_stream_find_channel
(
requested_channel
->
id
,
r
->
connection
->
log
,
mcf
);
}
}
// if specify a channels ids != ALL, get info about specified channels if they exists
// if specify a channels ids != ALL, get info about specified channels if they exists
...
...
src/ngx_http_push_stream_module_subscriber.c
View file @
a61b7a0c
This diff is collapsed.
Click to expand it.
src/ngx_http_push_stream_module_utils.c
View file @
a61b7a0c
...
@@ -336,32 +336,22 @@ ngx_http_push_stream_convert_char_to_msg_on_shared_locked(ngx_http_push_stream_m
...
@@ -336,32 +336,22 @@ ngx_http_push_stream_convert_char_to_msg_on_shared_locked(ngx_http_push_stream_m
}
}
ngx_
http_push_stream_channel_t
*
ngx_
int_t
ngx_http_push_stream_add_msg_to_channel
(
ngx_http_request_t
*
r
,
ngx_
str_t
*
id
,
u_char
*
text
,
size_t
len
,
ngx_str_t
*
event_id
,
ngx_str_t
*
event_type
,
ngx_pool_t
*
temp_pool
)
ngx_http_push_stream_add_msg_to_channel
(
ngx_http_request_t
*
r
,
ngx_
http_push_stream_channel_t
*
channel
,
u_char
*
text
,
size_t
len
,
ngx_str_t
*
event_id
,
ngx_str_t
*
event_type
,
ngx_pool_t
*
temp_pool
)
{
{
ngx_http_push_stream_main_conf_t
*
mcf
=
ngx_http_get_module_main_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_main_conf_t
*
mcf
=
ngx_http_get_module_main_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_http_push_stream_channel_t
*
channel
;
ngx_http_push_stream_msg_t
*
msg
;
ngx_http_push_stream_msg_t
*
msg
;
ngx_shmtx_lock
(
&
shpool
->
mutex
);
ngx_shmtx_lock
(
&
shpool
->
mutex
);
// just find the channel. if it's not there, NULL and return error.
channel
=
ngx_http_push_stream_find_channel
(
id
,
r
->
connection
->
log
,
mcf
);
if
(
channel
==
NULL
)
{
ngx_shmtx_unlock
(
&
(
shpool
)
->
mutex
);
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: something goes very wrong, arrived on ngx_http_push_stream_publisher_body_handler without created channel %s"
,
id
->
data
);
return
NULL
;
}
// create a buffer copy in shared mem
// create a buffer copy in shared mem
msg
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
mcf
,
text
,
len
,
channel
,
channel
->
last_message_id
+
1
,
event_id
,
event_type
,
temp_pool
);
msg
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
mcf
,
text
,
len
,
channel
,
channel
->
last_message_id
+
1
,
event_id
,
event_type
,
temp_pool
);
if
(
msg
==
NULL
)
{
if
(
msg
==
NULL
)
{
ngx_shmtx_unlock
(
&
(
shpool
)
->
mutex
);
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: unable to allocate message in shared memory"
);
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: unable to allocate message in shared memory"
);
return
N
ULL
;
return
N
GX_ERROR
;
}
}
channel
->
last_message_id
++
;
channel
->
last_message_id
++
;
...
@@ -392,7 +382,7 @@ ngx_http_push_stream_add_msg_to_channel(ngx_http_request_t *r, ngx_str_t *id, u_
...
@@ -392,7 +382,7 @@ ngx_http_push_stream_add_msg_to_channel(ngx_http_request_t *r, ngx_str_t *id, u_
// turn on timer to cleanup buffer of old messages
// turn on timer to cleanup buffer of old messages
ngx_http_push_stream_buffer_cleanup_timer_set
(
cf
);
ngx_http_push_stream_buffer_cleanup_timer_set
(
cf
);
return
channel
;
return
NGX_OK
;
}
}
...
@@ -845,19 +835,17 @@ ngx_http_push_stream_send_websocket_close_frame(ngx_http_request_t *r, ngx_uint_
...
@@ -845,19 +835,17 @@ ngx_http_push_stream_send_websocket_close_frame(ngx_http_request_t *r, ngx_uint_
}
}
static
ngx_flag_t
static
ngx_flag_t
ngx_http_push_stream_delete_channel
(
ngx_http_push_stream_main_conf_t
*
mcf
,
ngx_
str_t
*
id
,
u_char
*
text
,
size_t
len
,
ngx_pool_t
*
temp_pool
)
ngx_http_push_stream_delete_channel
(
ngx_http_push_stream_main_conf_t
*
mcf
,
ngx_
http_push_stream_channel_t
*
channel
,
u_char
*
text
,
size_t
len
,
ngx_pool_t
*
temp_pool
)
{
{
ngx_http_push_stream_channel_t
*
channel
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_http_push_stream_pid_queue_t
*
worker
;
ngx_http_push_stream_pid_queue_t
*
worker
;
ngx_queue_t
*
q
;
ngx_queue_t
*
q
;
ngx_flag_t
deleted
=
0
;
ngx_shmtx_lock
(
&
shpool
->
mutex
);
ngx_shmtx_lock
(
&
shpool
->
mutex
);
if
((
channel
!=
NULL
)
&&
!
channel
->
deleted
)
{
channel
=
ngx_http_push_stream_find_channel
(
id
,
ngx_cycle
->
log
,
mcf
);
deleted
=
1
;
if
(
channel
!=
NULL
)
{
// remove channel from tree
channel
->
deleted
=
1
;
channel
->
deleted
=
1
;
(
channel
->
wildcard
)
?
NGX_HTTP_PUSH_STREAM_DECREMENT_COUNTER
(
data
->
wildcard_channels
)
:
NGX_HTTP_PUSH_STREAM_DECREMENT_COUNTER
(
data
->
channels
);
(
channel
->
wildcard
)
?
NGX_HTTP_PUSH_STREAM_DECREMENT_COUNTER
(
data
->
wildcard_channels
)
:
NGX_HTTP_PUSH_STREAM_DECREMENT_COUNTER
(
data
->
channels
);
...
@@ -867,13 +855,12 @@ ngx_http_push_stream_delete_channel(ngx_http_push_stream_main_conf_t *mcf, ngx_s
...
@@ -867,13 +855,12 @@ ngx_http_push_stream_delete_channel(ngx_http_push_stream_main_conf_t *mcf, ngx_s
ngx_queue_insert_tail
(
&
data
->
channels_to_delete
,
&
channel
->
queue
);
ngx_queue_insert_tail
(
&
data
->
channels_to_delete
,
&
channel
->
queue
);
channel
->
queue_sentinel
=
&
data
->
channels_to_delete
;
channel
->
queue_sentinel
=
&
data
->
channels_to_delete
;
// remove all messages
// remove all messages
ngx_http_push_stream_ensure_qtd_of_messages_locked
(
data
,
channel
,
0
,
0
);
ngx_http_push_stream_ensure_qtd_of_messages_locked
(
data
,
channel
,
0
,
0
);
// apply channel deleted message text to message template
// apply channel deleted message text to message template
if
((
channel
->
channel_deleted_message
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
mcf
,
text
,
len
,
channel
,
NGX_HTTP_PUSH_STREAM_CHANNEL_DELETED_MESSAGE_ID
,
NULL
,
NULL
,
temp_pool
))
==
NULL
)
{
if
((
channel
->
channel_deleted_message
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
mcf
,
text
,
len
,
channel
,
NGX_HTTP_PUSH_STREAM_CHANNEL_DELETED_MESSAGE_ID
,
NULL
,
NULL
,
temp_pool
))
==
NULL
)
{
ngx_shmtx_unlock
(
&
(
shpool
)
->
mutex
);
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
ngx_log_error
(
NGX_LOG_ERR
,
temp_pool
->
log
,
0
,
"push stream module: unable to allocate memory to channel deleted message"
);
ngx_log_error
(
NGX_LOG_ERR
,
temp_pool
->
log
,
0
,
"push stream module: unable to allocate memory to channel deleted message"
);
return
0
;
return
0
;
}
}
...
@@ -889,8 +876,8 @@ ngx_http_push_stream_delete_channel(ngx_http_push_stream_main_conf_t *mcf, ngx_s
...
@@ -889,8 +876,8 @@ ngx_http_push_stream_delete_channel(ngx_http_push_stream_main_conf_t *mcf, ngx_s
}
}
}
}
ngx_shmtx_unlock
(
&
(
shpool
)
->
mutex
);
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
return
(
channel
!=
NULL
)
;
return
deleted
;
}
}
...
...
src/ngx_http_push_stream_module_websocket.c
View file @
a61b7a0c
...
@@ -292,7 +292,7 @@ ngx_http_push_stream_websocket_reading(ngx_http_request_t *r)
...
@@ -292,7 +292,7 @@ ngx_http_push_stream_websocket_reading(ngx_http_request_t *r)
for
(
q
=
ngx_queue_head
(
&
ctx
->
subscriber
->
subscriptions
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
subscriber
->
subscriptions
);
q
=
ngx_queue_next
(
q
))
{
for
(
q
=
ngx_queue_head
(
&
ctx
->
subscriber
->
subscriptions
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
subscriber
->
subscriptions
);
q
=
ngx_queue_next
(
q
))
{
ngx_http_push_stream_subscription_t
*
subscription
=
ngx_queue_data
(
q
,
ngx_http_push_stream_subscription_t
,
queue
);
ngx_http_push_stream_subscription_t
*
subscription
=
ngx_queue_data
(
q
,
ngx_http_push_stream_subscription_t
,
queue
);
if
(
ngx_http_push_stream_add_msg_to_channel
(
r
,
&
subscription
->
channel
->
id
,
ctx
->
frame
->
payload
,
ctx
->
frame
->
payload_len
,
NULL
,
NULL
,
ctx
->
temp_pool
)
==
NULL
)
{
if
(
ngx_http_push_stream_add_msg_to_channel
(
r
,
subscription
->
channel
,
ctx
->
frame
->
payload
,
ctx
->
frame
->
payload_len
,
NULL
,
NULL
,
ctx
->
temp_pool
)
!=
NGX_OK
)
{
ngx_http_finalize_request
(
r
,
NGX_OK
);
ngx_http_finalize_request
(
r
,
NGX_OK
);
return
;
return
;
}
}
...
...
src/ngx_http_push_stream_rbtree_util.c
View file @
a61b7a0c
...
@@ -76,6 +76,7 @@ ngx_http_push_stream_find_channel_on_tree(ngx_str_t *id, ngx_log_t *log, ngx_rbt
...
@@ -76,6 +76,7 @@ ngx_http_push_stream_find_channel_on_tree(ngx_str_t *id, ngx_log_t *log, ngx_rbt
static
ngx_http_push_stream_channel_t
*
static
ngx_http_push_stream_channel_t
*
ngx_http_push_stream_find_channel
(
ngx_str_t
*
id
,
ngx_log_t
*
log
,
ngx_http_push_stream_main_conf_t
*
mcf
)
ngx_http_push_stream_find_channel
(
ngx_str_t
*
id
,
ngx_log_t
*
log
,
ngx_http_push_stream_main_conf_t
*
mcf
)
{
{
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_http_push_stream_shm_data_t
*
data
=
mcf
->
shm_data
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
...
@@ -84,7 +85,9 @@ ngx_http_push_stream_find_channel(ngx_str_t *id, ngx_log_t *log, ngx_http_push_s
...
@@ -84,7 +85,9 @@ ngx_http_push_stream_find_channel(ngx_str_t *id, ngx_log_t *log, ngx_http_push_s
return
NULL
;
return
NULL
;
}
}
ngx_shmtx_lock
(
&
shpool
->
mutex
);
channel
=
ngx_http_push_stream_find_channel_on_tree
(
id
,
log
,
&
data
->
tree
);
channel
=
ngx_http_push_stream_find_channel_on_tree
(
id
,
log
,
&
data
->
tree
);
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
if
((
channel
==
NULL
)
||
channel
->
deleted
)
{
if
((
channel
==
NULL
)
||
channel
->
deleted
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -102,15 +105,15 @@ ngx_http_push_stream_get_channel(ngx_str_t *id, ngx_log_t *log, ngx_http_push_st
...
@@ -102,15 +105,15 @@ ngx_http_push_stream_get_channel(ngx_str_t *id, ngx_log_t *log, ngx_http_push_st
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_slab_pool_t
*
shpool
=
mcf
->
shpool
;
ngx_flag_t
is_wildcard_channel
=
0
;
ngx_flag_t
is_wildcard_channel
=
0
;
channel
=
ngx_http_push_stream_find_channel
(
id
,
log
,
mcf
);
if
(
id
==
NULL
)
{
if
(
channel
!=
NULL
)
{
// we found our channel
ngx_log_error
(
NGX_LOG_ERR
,
log
,
0
,
"push stream module: tried to create a channel with a null id"
);
return
channel
;
return
NULL
;
}
}
ngx_shmtx_lock
(
&
shpool
->
mutex
);
ngx_shmtx_lock
(
&
shpool
->
mutex
);
// check again to see if any other worker didn't create the channel
// check again to see if any other worker didn't create the channel
channel
=
ngx_http_push_stream_find_channel
(
id
,
log
,
mcf
);
channel
=
ngx_http_push_stream_find_channel
_on_tree
(
id
,
log
,
&
data
->
tree
);
if
(
channel
!=
NULL
)
{
// we found our channel
if
(
channel
!=
NULL
)
{
// we found our channel
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
ngx_shmtx_unlock
(
&
shpool
->
mutex
);
return
channel
;
return
channel
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment