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
b21eaab5
Commit
b21eaab5
authored
Jul 31, 2011
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring ngx_http_push_stream_msg_t type members
parent
09827759
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
52 deletions
+19
-52
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+1
-2
ngx_http_push_stream_module_utils.h
include/ngx_http_push_stream_module_utils.h
+1
-1
ngx_http_push_stream_module_utils.c
src/ngx_http_push_stream_module_utils.c
+17
-49
No files found.
include/ngx_http_push_stream_module.h
View file @
b21eaab5
...
...
@@ -78,12 +78,11 @@ static ngx_str_t ngx_http_push_stream_shm_name = ngx_string("push_stream_modu
// message queue
typedef
struct
{
ngx_queue_t
queue
;
// this MUST be first
ngx_buf_t
*
buf
;
time_t
expires
;
time_t
time
;
ngx_flag_t
deleted
;
ngx_int_t
id
;
ngx_str_t
raw
;
ngx_str_t
*
raw
;
ngx_str_t
*
formatted_messages
;
}
ngx_http_push_stream_msg_t
;
...
...
include/ngx_http_push_stream_module_utils.h
View file @
b21eaab5
...
...
@@ -206,7 +206,7 @@ static ngx_int_t ngx_http_push_stream_send_only_header_response(ngx_h
static
u_char
*
ngx_http_push_stream_str_replace
(
u_char
*
org
,
u_char
*
find
,
u_char
*
replace
,
ngx_uint_t
offset
,
ngx_pool_t
*
temp_pool
);
static
ngx_str_t
*
ngx_http_push_stream_get_formatted_chunk
(
const
u_char
*
text
,
off_t
len
,
ngx_pool_t
*
temp_pool
);
static
ngx_str_t
*
ngx_http_push_stream_get_formatted_message
(
ngx_http_request_t
*
r
,
ngx_http_push_stream_channel_t
*
channel
,
ngx_http_push_stream_msg_t
*
msg
,
ngx_pool_t
*
temp_pool
);
static
ngx_str_t
*
ngx_http_push_stream_format_message
(
ngx_http_push_stream_channel_t
*
channel
,
ngx_http_push_stream_msg_t
*
message
,
ngx_str_t
*
message_template
,
ngx_pool_t
*
temp_pool
);
static
ngx_str_t
*
ngx_http_push_stream_format_message
(
ngx_http_push_stream_channel_t
*
channel
,
ngx_http_push_stream_msg_t
*
message
,
ngx_str_t
*
text
,
ngx_str_t
*
message_template
,
ngx_pool_t
*
temp_pool
);
static
ngx_int_t
ngx_http_push_stream_send_response_content_header
(
ngx_http_request_t
*
r
,
ngx_http_push_stream_loc_conf_t
*
pslcf
);
static
ngx_int_t
ngx_http_push_stream_send_response_text
(
ngx_http_request_t
*
r
,
const
u_char
*
text
,
uint
len
,
ngx_flag_t
last_buffer
);
static
ngx_int_t
ngx_http_push_stream_send_ping
(
ngx_log_t
*
log
,
ngx_http_push_stream_loc_conf_t
*
pslcf
);
...
...
src/ngx_http_push_stream_module_utils.c
View file @
b21eaab5
...
...
@@ -148,38 +148,29 @@ ngx_http_push_stream_convert_char_to_msg_on_shared_locked(u_char *data, size_t l
msg
->
formatted_messages
=
NULL
;
if
((
msg
->
buf
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_buf_t
)
))
==
NULL
)
{
if
((
msg
->
raw
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_str_t
)
+
len
+
1
))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
if
((
msg
->
buf
->
start
=
ngx_slab_alloc_locked
(
shpool
,
len
+
1
))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
ngx_memset
(
msg
->
buf
->
start
,
'\0'
,
len
+
1
);
msg
->
raw
->
len
=
len
;
msg
->
raw
->
data
=
(
u_char
*
)
(
msg
->
raw
+
1
);
ngx_memset
(
msg
->
raw
->
data
,
'\0'
,
len
+
1
);
// copy the message to shared memory
msg
->
buf
->
last
=
ngx_copy
(
msg
->
buf
->
start
,
data
,
len
);
ngx_memcpy
(
msg
->
raw
->
data
,
data
,
len
);
msg
->
buf
->
pos
=
msg
->
buf
->
start
;
msg
->
buf
->
end
=
msg
->
buf
->
last
;
msg
->
buf
->
temporary
=
1
;
msg
->
buf
->
memory
=
1
;
msg
->
deleted
=
0
;
msg
->
expires
=
0
;
msg
->
queue
.
prev
=
NULL
;
msg
->
queue
.
next
=
NULL
;
msg
->
id
=
id
;
msg
->
raw
.
data
=
msg
->
buf
->
start
;
msg
->
raw
.
len
=
len
;
if
((
msg
->
formatted_messages
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_str_t
)
*
ngx_http_push_stream_module_main_conf
->
qtd_templates
))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
while
((
cur
=
(
ngx_http_push_stream_template_queue_t
*
)
ngx_queue_next
(
&
cur
->
queue
))
!=
sentinel
)
{
ngx_str_t
*
aux
=
ngx_http_push_stream_format_message
(
channel
,
msg
,
cur
->
template
,
temp_pool
);
ngx_str_t
*
aux
=
ngx_http_push_stream_format_message
(
channel
,
msg
,
msg
->
raw
,
cur
->
template
,
temp_pool
);
if
(
aux
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
...
...
@@ -520,8 +511,7 @@ ngx_http_push_stream_free_message_memory_locked(ngx_slab_pool_t *shpool, ngx_htt
ngx_slab_free_locked
(
shpool
,
msg
->
formatted_messages
);
}
if
((
msg
->
buf
!=
NULL
)
&&
(
msg
->
buf
->
start
!=
NULL
))
ngx_slab_free_locked
(
shpool
,
msg
->
buf
->
start
);
if
(
msg
->
buf
!=
NULL
)
ngx_slab_free_locked
(
shpool
,
msg
->
buf
);
if
(
msg
->
raw
!=
NULL
)
ngx_slab_free_locked
(
shpool
,
msg
->
raw
);
if
(
msg
!=
NULL
)
ngx_slab_free_locked
(
shpool
,
msg
);
}
...
...
@@ -711,54 +701,32 @@ ngx_http_push_stream_get_formatted_message(ngx_http_request_t *r, ngx_http_push_
if
(
pslcf
->
message_template_index
>
0
)
{
return
message
->
formatted_messages
+
pslcf
->
message_template_index
-
1
;
}
return
&
message
->
raw
;
return
message
->
raw
;
}
static
ngx_str_t
*
ngx_http_push_stream_format_message
(
ngx_http_push_stream_channel_t
*
channel
,
ngx_http_push_stream_msg_t
*
message
,
ngx_str_t
*
message_template
,
ngx_pool_t
*
pool
)
ngx_http_push_stream_format_message
(
ngx_http_push_stream_channel_t
*
channel
,
ngx_http_push_stream_msg_t
*
message
,
ngx_str_t
*
text
,
ngx_str_t
*
message_template
,
ngx_pool_t
*
temp_
pool
)
{
ngx_uint_t
len
=
0
;
u_char
*
txt
=
NULL
;
ngx_str_t
*
str
=
NULL
;
u_char
template
[
message_template
->
len
+
1
];
ngx_memset
(
template
,
'\0'
,
message_template
->
len
+
1
);
ngx_memcpy
(
template
,
message_template
->
data
,
message_template
->
len
);
u_char
char_id
[
NGX_INT_T_LEN
];
ngx_memset
(
char_id
,
'\0'
,
NGX_INT_T_LEN
);
u_char
*
msg
=
NGX_HTTP_PUSH_STREAM_EMPTY
.
data
;
u_char
*
channel_id
=
NGX_HTTP_PUSH_STREAM_EMPTY
.
data
;
ngx_int_t
message_id
=
0
;
if
(
channel
!=
NULL
)
{
channel_id
=
channel
->
id
.
data
;
}
if
(
message
!=
NULL
)
{
message_id
=
message
->
id
;
len
=
ngx_buf_size
(
message
->
buf
);
if
((
msg
=
ngx_pcalloc
(
pool
,
len
+
1
))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to copy message text"
);
return
NULL
;
}
ngx_memset
(
msg
,
'\0'
,
len
+
1
);
ngx_memcpy
(
msg
,
message
->
buf
->
pos
,
len
);
}
u_char
*
channel_id
=
(
channel
!=
NULL
)
?
channel
->
id
.
data
:
NGX_HTTP_PUSH_STREAM_EMPTY
.
data
;
ngx_sprintf
(
char_id
,
"%d"
,
message
_
id
);
ngx_sprintf
(
char_id
,
"%d"
,
message
->
id
);
txt
=
ngx_http_push_stream_str_replace
(
template
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_ID
.
data
,
char_id
,
0
,
pool
);
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL
.
data
,
channel_id
,
0
,
pool
);
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT
.
data
,
msg
,
0
,
pool
);
txt
=
ngx_http_push_stream_str_replace
(
message_template
->
data
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_ID
.
data
,
char_id
,
0
,
temp_
pool
);
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL
.
data
,
channel_id
,
0
,
temp_
pool
);
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT
.
data
,
text
->
data
,
0
,
temp_
pool
);
if
(
txt
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to replace message values on template"
);
ngx_log_error
(
NGX_LOG_ERR
,
temp_
pool
->
log
,
0
,
"push stream module: unable to allocate memory to replace message values on template"
);
return
NULL
;
}
if
((
str
=
ngx_pcalloc
(
pool
,
sizeof
(
ngx_str_t
)))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to return message applied to template"
);
if
((
str
=
ngx_pcalloc
(
temp_
pool
,
sizeof
(
ngx_str_t
)))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
temp_
pool
->
log
,
0
,
"push stream module: unable to allocate memory to return message applied to template"
);
return
NULL
;
}
str
->
data
=
txt
;
...
...
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