Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing procedure improvements, several fixes #334

Merged
merged 95 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
dabbfa6
Reafactor sending methods - wip - bb test
weinrank Apr 25, 2017
10b393c
Wait until all data has been drained until calling shutdown on socket
weinrank Apr 25, 2017
60e5e4d
Cleanup
weinrank Apr 26, 2017
cc23222
refactoring and bugfixes for clinet_http_run_once
weinrank Apr 26, 2017
0781e1b
call io_all_written only if neat_write has been called prior and do t…
weinrank Apr 26, 2017
b51b97b
docs
weinrank Apr 26, 2017
1ca65c8
client_http_get : free stat
weinrank Apr 26, 2017
7821edf
Merge branch 'weinrank/fixes' of github.com:NEAT-project/neat into we…
weinrank Apr 26, 2017
e0adbd1
Merge branch 'master' into weinrank/fixes
weinrank May 5, 2017
511902f
Refactoring - sync wip
weinrank May 5, 2017
c47fb50
CMAKE from DTLS Branch
weinrank May 7, 2017
022496c
call on_close when peer has disconnected
weinrank May 7, 2017
fdf6255
http_client - print statistics when on_close has been called
weinrank May 7, 2017
bdf109d
closing procedure improvements
weinrank May 7, 2017
30bd0a9
neat closing refactoring
weinrank May 8, 2017
f60a458
Merge branch 'master' into weinrank/fixes
weinrank May 8, 2017
42f3ef7
Merge branch 'weinrank/fixes' of github.com:NEAT-project/neat into we…
weinrank May 8, 2017
57cef76
sync upstream CMAKE file
weinrank May 8, 2017
cf1e05a
sync wip
weinrank May 8, 2017
a6d1f20
sync - wip
weinrank May 8, 2017
1420621
improve closing mechanism
weinrank May 8, 2017
195aa46
remove stats timer
weinrank May 8, 2017
94dcd9c
tneat for new semantic
weinrank May 9, 2017
8bd3fa8
tneat improvements
weinrank May 9, 2017
3110d23
tneat improvements
weinrank May 9, 2017
3ee9b8d
flow closing improvements
weinrank May 9, 2017
0936dc7
check if handle->data exists
weinrank May 9, 2017
28828d5
revert assert check for pollable socket
weinrank May 9, 2017
a6d6865
new closing semantic for SCTP flows
weinrank May 9, 2017
eede9cf
asserts for usrsctp bugs
weinrank May 9, 2017
549ebaf
silence valgrind complains about openssl
weinrank May 9, 2017
6c34187
test for HTTPS added
weinrank May 9, 2017
1616014
testpath fix
weinrank May 9, 2017
463f038
socket.io lib as submodule
weinrank May 9, 2017
5156f5d
Revert "socket.io lib as submodule"
weinrank May 9, 2017
c0bf16d
neat_new_flow refactoring
weinrank May 9, 2017
a5ee69b
minor refactoring
weinrank May 9, 2017
0f146c7
improve closing mechanism
weinrank May 9, 2017
64406ce
http client: stop event loop if error
weinrank May 9, 2017
b162dd7
http client: stop event loop if error
weinrank May 9, 2017
8b13514
closing improvements
weinrank May 9, 2017
5e9b6d2
usrsctp fix
weinrank May 9, 2017
3ef0e26
tneat and client_run_once refactoring
weinrank May 10, 2017
6b96f07
client_http_run_once polish
weinrank May 10, 2017
476ef31
CMAKE changes
weinrank May 10, 2017
85d671c
revert CMAKE path changes
weinrank May 10, 2017
254ed55
message boundary preservation added
weinrank May 10, 2017
4d2ff9c
Merge branch 'weinrank/fixes' of github.com:NEAT-project/neat into we…
weinrank May 10, 2017
c9f68d5
do not require message preserving for HTTP
weinrank May 10, 2017
3516f9e
improve usrsctp support
weinrank May 10, 2017
53ff18e
address use after free bug
weinrank May 10, 2017
87796e7
address use after free - second try
weinrank May 10, 2017
dabb8a6
examples updated
weinrank May 10, 2017
f4d0cfe
client improvements
weinrank May 10, 2017
444dbb3
docs updated
weinrank May 10, 2017
681b786
improve closing procedure for usrsctp
May 11, 2017
93907fb
Merge branch 'master' into weinrank/fixes
weinrank May 16, 2017
b3add11
close socket for unsused candidates
weinrank May 17, 2017
ca160d5
minor refactoring
weinrank May 17, 2017
dcaa482
reduce timeout span and improve closing procedure
weinrank May 18, 2017
083faee
polish - no functional changes
weinrank May 18, 2017
7ade86d
avoid asprintf
weinrank May 19, 2017
15e8983
buffersize via macro
weinrank May 19, 2017
0ccfa9b
fix explicit EOR on server side
weinrank May 19, 2017
627da83
http server refactoring - wip
weinrank May 19, 2017
7783d58
http server refactoring
weinrank May 19, 2017
9e4ef49
minor refactoring
weinrank May 20, 2017
450233f
https support for webserver
weinrank May 22, 2017
b1c8fdd
fix compile error
weinrank May 22, 2017
813846f
fix compile error
weinrank May 22, 2017
e98a261
Merge branch 'master' into weinrank/fixes
weinrank May 23, 2017
816f602
Merge branch 'master' into weinrank/fixes
weinrank May 30, 2017
a82eaa6
calloc fix
weinrank Jun 11, 2017
f6664c6
tneat - loop
weinrank Jun 11, 2017
bd6465c
tneat - fixes
weinrank Jun 11, 2017
6998e07
tneat - use after free fix
weinrank Jun 11, 2017
d8f44d4
bb sync
weinrank Jun 12, 2017
00c037f
tneat - portfix
weinrank Jun 12, 2017
5c17638
bb tests
weinrank Jun 12, 2017
aa3db21
sctp tests only for supported platforms
weinrank Jun 12, 2017
6aa2fbc
Enable multistreaming by default
weinrank Jun 12, 2017
961e758
calloc and tneat fix
weinrank Jun 14, 2017
1002361
Merge branch 'master' into weinrank/fixes
weinrank Jun 15, 2017
c68d433
CMAKE changes
weinrank Jun 15, 2017
0efe869
bb test
weinrank Jun 15, 2017
987ce70
revert bb test
weinrank Jun 16, 2017
7db2496
tneat tests less verbose
weinrank Jun 16, 2017
ad5501d
tneat self test for sctp removed
weinrank Jun 19, 2017
0555172
tneat self test for tcp removed
weinrank Jun 19, 2017
de7e22a
added feature: unordered transmission
weinrank Jun 19, 2017
adbcf09
PR extension for SCTP
weinrank Jun 19, 2017
db8df46
partial reliability fix for linux
weinrank Jun 19, 2017
07f3e70
compile fix for netbsd
weinrank Jun 19, 2017
14586a6
Merge branch 'master' into weinrank/fixes
weinrank Jun 20, 2017
2f44d61
fix merge error for client_http_get.c
weinrank Jun 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ include(CPack)

add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} clean package_source)


INCLUDE(CheckIncludeFile)
INCLUDE(CheckStructHasMember)
INCLUDE(CheckTypeSize)
Expand Down Expand Up @@ -179,11 +178,15 @@ IF (FLOW_GROUPS)
ADD_DEFINITIONS(-DFLOW_GROUPS)
ENDIF()

OPTION(SCTP_MULTISTREAMING "Include support for SCTP multistreaming" 1)
OPTION(SCTP_MULTISTREAMING "Include support for SCTP multistreaming" 0)
IF (SCTP_MULTISTREAMING)
ADD_DEFINITIONS(-DSCTP_MULTISTREAMING)
ENDIF()

OPTION(OPENSSL_SUPPORT "Include support for OpenSSL" 1)

OPTION(SOCKET_API "Include the socket API" 0)

# REQUIREMENTS
#################################################
CHECK_INCLUDE_FILE(uv.h HAVE_SYS_UV_H)
Expand All @@ -203,27 +206,29 @@ ELSE()
MESSAGE("LDNS found: " ${LDNS_LIB})
ENDIF()

FIND_PACKAGE(OpenSSL)
IF (NOT OPENSSL_FOUND)
MESSAGE(WARNING "openssl >= 1.0.2 required for TLS - none found")
ELSE()
MESSAGE("OPENSSL version found: " ${OPENSSL_VERSION})
IF (OPENSSL_VERSION VERSION_LESS "1.0.2")
MESSAGE(WARNING "openssl >= 1.0.2 required for TLS")
IF (OPENSSL_SUPPORT)
FIND_PACKAGE(OpenSSL)
IF (NOT OPENSSL_FOUND)
MESSAGE(WARNING "openssl >= 1.0.2 required for TLS - none found")
ELSE()
CHECK_INCLUDE_FILE(openssl/ssl.h HAVE_SYS_OPENSSL_H)
MESSAGE(STATUS "OPENSSL Crypto found: " ${OPENSSL_LIBRARIES})
ADD_DEFINITIONS(-DNEAT_USETLS)
SET(CMAKE_EXTRA_INCLUDE_FILES "openssl/ssl.h")

IF ((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
CHECK_TYPE_SIZE("struct bio_dgram_sctp_sndinfo" OPENSSL_DTLS)
IF (HAVE_OPENSSL_DTLS)
MESSAGE("DTLS for SCTP supported")
ADD_DEFINITIONS(-DNEAT_SCTP_DTLS)
MESSAGE("OPENSSL version found: " ${OPENSSL_VERSION})
IF (OPENSSL_VERSION VERSION_LESS "1.0.2")
MESSAGE(WARNING "openssl >= 1.0.2 required for TLS")
ELSE()
CHECK_INCLUDE_FILE(openssl/ssl.h HAVE_SYS_OPENSSL_H)
MESSAGE(STATUS "OPENSSL Crypto found: " ${OPENSSL_LIBRARIES})
ADD_DEFINITIONS(-DNEAT_USETLS)
SET(CMAKE_EXTRA_INCLUDE_FILES "openssl/ssl.h")

IF ((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
CHECK_TYPE_SIZE("struct bio_dgram_sctp_sndinfo" OPENSSL_DTLS)
IF (HAVE_OPENSSL_DTLS)
MESSAGE("DTLS for SCTP supported")
ADD_DEFINITIONS(-DNEAT_SCTP_DTLS)
ENDIF()
ENDIF()
ENDIF()

ENDIF()
ENDIF()
ENDIF()

Expand Down Expand Up @@ -331,6 +336,8 @@ INSTALL(FILES ${neat_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# INCLUDE EXAMPLES AND TESTS FOLDER
#################################################
ADD_SUBDIRECTORY(socketapi)
IF (SOCKET_API)
ADD_SUBDIRECTORY(socketapi)
ENDIF()
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(tests)
2 changes: 1 addition & 1 deletion docs/neat_close.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# neat_close
Initiates the closing procedure for a flow.

Close this flow and free all associated data.

### Syntax

Expand Down
10 changes: 5 additions & 5 deletions docs/neat_read.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# neat_read

Read data from a neat flow. Should only be called from within the `on_readable`
Read data from a neat flow.

Should only be called from within the `on_readable`
callback specified with `neat_set_operations`.

```c
Expand Down Expand Up @@ -41,11 +43,9 @@ parameter.

### Remarks

This function should only be called from within the `on_readable` callback
specified with `neat_set_operations`, as this is the only way to guarantee
that the call will not block. NEAT does not permit a blocking read operation.
This function should only be called from within the `on_readable` callback specified with `neat_set_operations`, as this is the only way to guarantee that the call will not block. NEAT does not permit a blocking read operation.

The **actual_amount** value is set to 0 when this function returns error.
The **actual_amount** value is set to 0 when the remote side has closed the connection.

### Examples

Expand Down
10 changes: 8 additions & 2 deletions docs/neat_shutdown.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# neat_shutdown

Initiate a graceful shutdown of this flow. All previously written data will be
sent. Data can still be read from the flow.
Initiate a graceful shutdown of this flow.

* the receive buffer can still be read and `on_readable` gets fired like in normal operation
* receiving **new** data from the peer **may** fail
* all data in the *send buffer* will be transmitted
* `neat_write` will fail and `on_writable` will not be called

If the peer also has closed the connection, the `on_close` callback gets fired.

### Syntax

Expand Down
13 changes: 8 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ LIST(APPEND neat_programs
client_data.c
client_http_get.c
client_http_run_once.c
client_https_get.c
server_chargen.c
server_daytime.c
server_discard.c
Expand All @@ -14,16 +13,22 @@ LIST(APPEND neat_programs
tneat.c
peer.c
msbench.c
minimal_client.c
minimal_server.c
minimal_server2.c
)

LIST(APPEND neat_property_examples
prop_all.json
prop_datagram.json
prop_default.json
prop_sctp.json
prop_sctp_dtls.json
prop_sctp_multihomed.json
prop_tcp.json
prop_sctp_dtls.json
prop_tcp_security.json
prop_streaming_mode.json
prop_message_mode.json
)

# BUILD EACH PROGRAM
Expand All @@ -34,11 +39,9 @@ FOREACH (source_file ${neat_programs})
${source_file_we}
${source_file}
util.c
picohttpparser.c
)
TARGET_LINK_LIBRARIES(${source_file_we} neat)
INSTALL(TARGETS ${source_file_we}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/libneat
BUNDLE DESTINATION ${CMAKE_INSTALL_LIBDIR}/libneat)
ENDFOREACH ()

# COPY EXAMPLE PROPERTY FILES
Expand Down
51 changes: 6 additions & 45 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,12 @@ on_readable(struct neat_flow_operations *opCB)
}
}

// all fine
if (buffer_filled > 0) {
if (config_log_level >= 1) {
fprintf(stderr, "%s - received %d bytes on stream id %d\n", __func__, buffer_filled, opCB->stream_id);
}
fwrite(buffer_rcv, sizeof(char), buffer_filled, stdout);
fflush(stdout);

} else {
fprintf(stderr, "%s - nothing more to read\n", __func__);
ops.on_readable = NULL;
neat_set_operations(opCB->ctx, opCB->flow, &ops);
neat_close(opCB->ctx, opCB->flow);
if (config_log_level >= 1) {
fprintf(stderr, "%s - received %d bytes on stream id %d\n", __func__, buffer_filled, opCB->stream_id);
}
fwrite(buffer_rcv, sizeof(char), buffer_filled, stdout);
fflush(stdout);

return NEAT_OK;
}
Expand Down Expand Up @@ -255,12 +247,6 @@ on_connected(struct neat_flow_operations *opCB)
int rc;
uv_loop_t *loop;

/*
if (config_log_level >= 1) {
printf("%s - available streams : %d\n", __func__, opCB->flow->stream_count);
}
*/

last_stream = 0;
loop = neat_get_event_loop(opCB->ctx);

Expand All @@ -281,8 +267,9 @@ on_connected(struct neat_flow_operations *opCB)
}
}

if (config_timeout)
if (config_timeout) {
neat_change_timeout(opCB->ctx, opCB->flow, config_timeout);
}

return NEAT_OK;
}
Expand Down Expand Up @@ -332,35 +319,9 @@ tty_read(uv_stream_t *stream, ssize_t buffer_filled, const uv_buf_t *buffer)
if (!uv_is_closing((uv_handle_t*) &tty)) {
uv_close((uv_handle_t*) &tty, NULL);
}
neat_shutdown(ctx, flow);
} else if (strncmp(buffer->base, "close\n", buffer_filled) == 0) {
if (config_log_level >= 1) {
fprintf(stderr, "%s - tty_read - CLOSE\n", __func__);
}
uv_read_stop(stream);
ops.on_writable = NULL;
neat_set_operations(ctx, flow, &ops);
if (!uv_is_closing((uv_handle_t*) &tty)) {
uv_close((uv_handle_t*) &tty, NULL);
}
neat_close(ctx, flow);
buffer_filled = UV_EOF;
} else if (strncmp(buffer->base, "abort\n", buffer_filled) == 0) {
if (config_log_level >= 1) {
fprintf(stderr, "%s - tty_read - ABORT\n", __func__);
}
uv_read_stop(stream);
ops.on_writable = NULL;
neat_set_operations(ctx, flow, &ops);
if (!uv_is_closing((uv_handle_t*) &tty)) {
uv_close((uv_handle_t*) &tty, NULL);
}
neat_abort(ctx, flow);
buffer_filled = UV_EOF;
}

fprintf(stderr, "%s - felix - marker\n", __func__);

// all fine
if (buffer_filled > 0 && buffer_filled != UV_EOF) {
// copy input to app buffer
Expand Down
Loading