Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
02924b6d
Commit
02924b6d
authored
Mar 10, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added spdylay_submit_settings
parent
82e20192
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
176 additions
and
2 deletions
+176
-2
lib/includes/spdylay/spdylay.h
lib/includes/spdylay/spdylay.h
+19
-2
lib/spdylay_frame.c
lib/spdylay_frame.c
+11
-0
lib/spdylay_frame.h
lib/spdylay_frame.h
+7
-0
lib/spdylay_session.c
lib/spdylay_session.c
+12
-0
lib/spdylay_session.h
lib/spdylay_session.h
+10
-0
lib/spdylay_submit.c
lib/spdylay_submit.c
+40
-0
tests/main.c
tests/main.c
+2
-0
tests/spdylay_session_test.c
tests/spdylay_session_test.c
+74
-0
tests/spdylay_session_test.h
tests/spdylay_session_test.h
+1
-0
No files found.
lib/includes/spdylay/spdylay.h
View file @
02924b6d
...
...
@@ -662,7 +662,7 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session,
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* SPDYLAY_ERR_INVALID_
FRAME
* SPDYLAY_ERR_INVALID_
ARGUMENT
* |pri| is invalid.
* SPDYLAY_ERR_NOMEM
* Out of memory.
...
...
@@ -728,7 +728,7 @@ int spdylay_submit_response(spdylay_session *session,
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* SPDYLAY_ERR_INVALID_
FRAME
* SPDYLAY_ERR_INVALID_
ARGUMENT
* |pri| is invalid.
* SPDYLAY_ERR_NOMEM
* Out of memory.
...
...
@@ -830,6 +830,23 @@ int spdylay_submit_ping(spdylay_session *session);
*/
int
spdylay_submit_goaway
(
spdylay_session
*
session
,
uint32_t
status_code
);
/*
* Stores local settings and submits SETTINGS frame. The |iv| is the
* pointer to the array of spdylay_settings_entry. The |niv| indicates
* the number of spdylay_settings_entry. The |flags| is bitwise-OR of
* one or more values from spdylay_settings_flag.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* SPDYLAY_ERR_INVALID_ARGUMENT
* The |iv| contains duplicate settings ID or invalid value.
* SPDYLAY_ERR_NOMEM
* Out of memory.
*/
int
spdylay_submit_settings
(
spdylay_session
*
session
,
uint8_t
flags
,
const
spdylay_settings_entry
*
iv
,
size_t
niv
);
/*
* A helper function for dealing with NPN in client side.
* |in| contains server's protocol in preferable order.
...
...
lib/spdylay_frame.c
View file @
02924b6d
...
...
@@ -1000,3 +1000,14 @@ spdylay_settings_entry* spdylay_frame_iv_copy(const spdylay_settings_entry *iv,
memcpy
(
iv_copy
,
iv
,
len
);
return
iv_copy
;
}
static
int
spdylay_settings_entry_compar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
return
((
spdylay_settings_entry
*
)
lhs
)
->
settings_id
-
((
spdylay_settings_entry
*
)
rhs
)
->
settings_id
;
}
void
spdylay_frame_iv_sort
(
spdylay_settings_entry
*
iv
,
size_t
niv
)
{
qsort
(
iv
,
niv
,
sizeof
(
spdylay_settings_entry
),
spdylay_settings_entry_compar
);
}
lib/spdylay_frame.h
View file @
02924b6d
...
...
@@ -618,4 +618,11 @@ void spdylay_frame_nv_2to3(char **nv);
spdylay_settings_entry
*
spdylay_frame_iv_copy
(
const
spdylay_settings_entry
*
iv
,
size_t
niv
);
/*
* Sorts the |iv| with the ascending order of the settings_id member.
* The number of the element in the array pointed by the |iv| is given
* by the |niv|.
*/
void
spdylay_frame_iv_sort
(
spdylay_settings_entry
*
iv
,
size_t
niv
);
#endif
/* SPDYLAY_FRAME_H */
lib/spdylay_session.c
View file @
02924b6d
...
...
@@ -328,6 +328,7 @@ int spdylay_session_add_frame(spdylay_session *session,
}
case
SPDYLAY_SETTINGS
:
/* Should SPDYLAY_SETTINGS have higher priority? */
item
->
pri
=
-
1
;
break
;
case
SPDYLAY_NOOP
:
/* We don't have any public API to add NOOP, so here is
...
...
@@ -1542,6 +1543,17 @@ static void spdylay_session_update_initial_window_size
vals
);
}
void
spdylay_session_update_local_settings
(
spdylay_session
*
session
,
spdylay_settings_entry
*
iv
,
size_t
niv
)
{
int
i
;
for
(
i
=
0
;
i
<
niv
;
++
i
)
{
assert
(
iv
[
i
].
settings_id
>
0
&&
iv
[
i
].
settings_id
<=
SPDYLAY_SETTINGS_MAX
);
session
->
local_settings
[
iv
[
i
].
settings_id
]
=
iv
[
i
].
value
;
}
}
int
spdylay_session_on_settings_received
(
spdylay_session
*
session
,
spdylay_frame
*
frame
)
{
...
...
lib/spdylay_session.h
View file @
02924b6d
...
...
@@ -483,4 +483,14 @@ spdylay_outbound_item* spdylay_session_get_next_ob_item
*/
uint8_t
spdylay_session_get_pri_lowest
(
spdylay_session
*
session
);
/*
* Updates local settings with the |iv|. The number of elements in the
* array pointed by the |iv| is given by the |niv|. This function
* assumes that the all settings_id member in |iv| are in range 1 to
* SPDYLAY_SETTINGS_MAX, inclusive.
*/
void
spdylay_session_update_local_settings
(
spdylay_session
*
session
,
spdylay_settings_entry
*
iv
,
size_t
niv
);
#endif
/* SPDYLAY_SESSION_H */
lib/spdylay_submit.c
View file @
02924b6d
...
...
@@ -24,6 +24,8 @@
*/
#include "spdylay_submit.h"
#include <string.h>
#include "spdylay_session.h"
#include "spdylay_frame.h"
...
...
@@ -183,6 +185,44 @@ int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code)
status_code
);
}
int
spdylay_submit_settings
(
spdylay_session
*
session
,
uint8_t
flags
,
const
spdylay_settings_entry
*
iv
,
size_t
niv
)
{
spdylay_frame
*
frame
;
spdylay_settings_entry
*
iv_copy
;
int
check
[
SPDYLAY_SETTINGS_MAX
+
1
];
int
i
,
r
;
memset
(
check
,
0
,
sizeof
(
check
));
for
(
i
=
0
;
i
<
niv
;
++
i
)
{
if
(
iv
[
i
].
settings_id
>
SPDYLAY_SETTINGS_MAX
||
iv
[
i
].
settings_id
==
0
||
check
[
iv
[
i
].
settings_id
]
==
1
)
{
return
SPDYLAY_ERR_INVALID_ARGUMENT
;
}
else
{
check
[
iv
[
i
].
settings_id
]
=
1
;
}
}
frame
=
malloc
(
sizeof
(
spdylay_frame
));
if
(
frame
==
NULL
)
{
return
SPDYLAY_ERR_NOMEM
;
}
iv_copy
=
spdylay_frame_iv_copy
(
iv
,
niv
);
if
(
iv_copy
==
NULL
)
{
free
(
frame
);
return
SPDYLAY_ERR_NOMEM
;
}
spdylay_frame_iv_sort
(
iv_copy
,
niv
);
spdylay_frame_settings_init
(
&
frame
->
settings
,
session
->
version
,
flags
,
iv_copy
,
niv
);
r
=
spdylay_session_add_frame
(
session
,
SPDYLAY_SETTINGS
,
frame
,
NULL
);
if
(
r
==
0
)
{
spdylay_session_update_local_settings
(
session
,
iv_copy
,
niv
);
}
else
{
spdylay_frame_settings_free
(
&
frame
->
settings
);
free
(
frame
);
}
return
r
;
}
int
spdylay_submit_request
(
spdylay_session
*
session
,
uint8_t
pri
,
const
char
**
nv
,
const
spdylay_data_provider
*
data_prd
,
...
...
tests/main.c
View file @
02924b6d
...
...
@@ -140,6 +140,8 @@ int main(int argc, char* argv[])
test_spdylay_session_on_ctrl_not_send
)
||
!
CU_add_test
(
pSuite
,
"session_on_settings_received"
,
test_spdylay_session_on_settings_received
)
||
!
CU_add_test
(
pSuite
,
"session_submit_settings"
,
test_spdylay_submit_settings
)
||
!
CU_add_test
(
pSuite
,
"frame_unpack_nv_spdy2"
,
test_spdylay_frame_unpack_nv_spdy2
)
||
!
CU_add_test
(
pSuite
,
"frame_unpack_nv_spdy3"
,
...
...
tests/spdylay_session_test.c
View file @
02924b6d
...
...
@@ -1898,3 +1898,77 @@ void test_spdylay_session_on_settings_received()
spdylay_session_del
(
session
);
}
void
test_spdylay_submit_settings
()
{
spdylay_session
*
session
;
spdylay_session_callbacks
callbacks
;
my_user_data
ud
;
spdylay_outbound_item
*
item
;
spdylay_frame
*
frame
;
spdylay_settings_entry
iv
[
3
];
iv
[
0
].
settings_id
=
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
;
iv
[
0
].
value
=
50
;
iv
[
0
].
flags
=
SPDYLAY_ID_FLAG_SETTINGS_NONE
;
iv
[
1
].
settings_id
=
SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE
;
iv
[
1
].
value
=
16
*
1024
;
iv
[
1
].
flags
=
SPDYLAY_ID_FLAG_SETTINGS_NONE
;
/* This is duplicate entry */
iv
[
2
].
settings_id
=
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
;
iv
[
2
].
value
=
150
;
iv
[
2
].
flags
=
SPDYLAY_ID_FLAG_SETTINGS_NONE
;
memset
(
&
callbacks
,
0
,
sizeof
(
spdylay_session_callbacks
));
callbacks
.
send_callback
=
null_send_callback
;
callbacks
.
on_ctrl_send_callback
=
on_ctrl_send_callback
;
spdylay_session_server_new
(
&
session
,
SPDYLAY_PROTO_SPDY3
,
&
callbacks
,
&
ud
);
CU_ASSERT
(
SPDYLAY_ERR_INVALID_ARGUMENT
==
spdylay_submit_settings
(
session
,
SPDYLAY_FLAG_SETTINGS_NONE
,
iv
,
3
));
/* Make sure that local settings are not changed */
CU_ASSERT
(
SPDYLAY_CONCURRENT_STREAMS_MAX
==
session
->
local_settings
[
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
]);
CU_ASSERT
(
SPDYLAY_INITIAL_WINDOW_SIZE
==
session
->
local_settings
[
SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE
]);
CU_ASSERT
(
0
==
spdylay_submit_settings
(
session
,
SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS
,
iv
,
2
));
/* Make sure that local settings are changed */
CU_ASSERT
(
50
==
session
->
local_settings
[
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
]);
CU_ASSERT
(
16
*
1024
==
session
->
local_settings
[
SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE
]);
item
=
spdylay_session_get_next_ob_item
(
session
);
CU_ASSERT
(
SPDYLAY_SETTINGS
==
item
->
frame_type
);
frame
=
item
->
frame
;
CU_ASSERT
(
2
==
frame
->
settings
.
niv
);
CU_ASSERT
(
SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS
==
frame
->
settings
.
hd
.
flags
);
CU_ASSERT
(
50
==
frame
->
settings
.
iv
[
0
].
value
);
CU_ASSERT
(
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
==
frame
->
settings
.
iv
[
0
].
settings_id
);
CU_ASSERT
(
SPDYLAY_FLAG_SETTINGS_NONE
==
frame
->
settings
.
iv
[
0
].
flags
);
CU_ASSERT
(
16
*
1024
==
frame
->
settings
.
iv
[
1
].
value
);
CU_ASSERT
(
SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE
==
frame
->
settings
.
iv
[
1
].
settings_id
);
CU_ASSERT
(
SPDYLAY_FLAG_SETTINGS_NONE
==
frame
->
settings
.
iv
[
1
].
flags
);
ud
.
ctrl_send_cb_called
=
0
;
CU_ASSERT
(
0
==
spdylay_session_send
(
session
));
CU_ASSERT
(
1
==
ud
.
ctrl_send_cb_called
);
spdylay_session_del
(
session
);
}
tests/spdylay_session_test.h
View file @
02924b6d
...
...
@@ -62,5 +62,6 @@ void test_spdylay_session_defer_data();
void
test_spdylay_session_flow_control
();
void
test_spdylay_session_on_ctrl_not_send
();
void
test_spdylay_session_on_settings_received
();
void
test_spdylay_submit_settings
();
#endif // SPDYLAY_SESSION_TEST_H
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