Skip to content

Commit

Permalink
Merge pull request #334 from NEAT-project/weinrank/fixes
Browse files Browse the repository at this point in the history
Closing procedure improvements, several fixes
  • Loading branch information
weinrank authored Jun 20, 2017
2 parents feb4764 + 2f44d61 commit 55163c0
Show file tree
Hide file tree
Showing 31 changed files with 2,418 additions and 1,319 deletions.
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

0 comments on commit 55163c0

Please sign in to comment.