Skip to content

Commit

Permalink
Revert "handle sctp shutdown issue mentioned here: sctplab/usrsctp#147"
Browse files Browse the repository at this point in the history
This reverts commit 4e13ff8.
  • Loading branch information
chehefen committed Apr 8, 2020
1 parent e1cf453 commit 21cffc9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ matrix:
# Old Version GCC 4.4
- name: "Linux GCC 4.4 Build"
os: linux
before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get -q update
- sudo apt-get -y install gcc-4.4
- sudo apt-get -y install gdb
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.4
- gdb
compiler: gcc
before_script: export CC=gcc-4.4 && mkdir build && cd build && cmake .. -DBUILD_TEST=TRUE

Expand Down
27 changes: 5 additions & 22 deletions src/source/Sctp/Sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ STATUS createSctpSession(PSctpSessionCallbacks pSctpSessionCallbacks, PSctpSessi
MEMSET(&localConn, 0x00, SIZEOF(struct sockaddr_conn));
MEMSET(&remoteConn, 0x00, SIZEOF(struct sockaddr_conn));

ATOMIC_STORE(&pSctpSession->shutdownStatus, SCTP_SESSION_ACTIVE);
pSctpSession->sctpSessionCallbacks = *pSctpSessionCallbacks;

CHK_STATUS(initSctpAddrConn(pSctpSession, &localConn));
Expand Down Expand Up @@ -129,28 +128,16 @@ STATUS freeSctpSession(PSctpSession* ppSctpSession)
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
PSctpSession pSctpSession;
UINT64 shutdownTimeout;

CHK(ppSctpSession != NULL, STATUS_NULL_ARG);

pSctpSession = *ppSctpSession;

CHK(pSctpSession != NULL, retStatus);

usrsctp_deregister_address(pSctpSession);
/* handle issue mentioned here: https://github.com/sctplab/usrsctp/issues/147
* the change in shutdownStatus will trigger onSctpOutboundPacket to return -1 */
ATOMIC_STORE(&pSctpSession->shutdownStatus, SCTP_SESSION_SHUTDOWN_INITIATED);

if (pSctpSession->socket != NULL) {
usrsctp_set_ulpinfo(pSctpSession->socket, NULL);
usrsctp_shutdown (pSctpSession->socket, SHUT_RDWR);
usrsctp_close(pSctpSession->socket);
}

shutdownTimeout = GETTIME() + DEFAULT_SCTP_SHUTDOWN_TIMEOUT;
while(ATOMIC_LOAD(&pSctpSession->shutdownStatus) != SCTP_SESSION_SHUTDOWN_COMPLETED && GETTIME() < shutdownTimeout) {
THREAD_SLEEP(DEFAULT_USRSCTP_TEARDOWN_POLLING_INTERVAL);
usrsctp_deregister_address(pSctpSession);
}

SAFE_MEMFREE(*ppSctpSession);
Expand Down Expand Up @@ -222,16 +209,12 @@ INT32 onSctpOutboundPacket(PVOID addr, PVOID data, ULONG length, UINT8 tos, UINT

PSctpSession pSctpSession = (PSctpSession) addr;

if (pSctpSession == NULL || ATOMIC_LOAD(&pSctpSession->shutdownStatus) == SCTP_SESSION_SHUTDOWN_INITIATED ||
pSctpSession->sctpSessionCallbacks.outboundPacketFunc == NULL) {
if (pSctpSession != NULL) {
ATOMIC_STORE(&pSctpSession->shutdownStatus, SCTP_SESSION_SHUTDOWN_COMPLETED);
}
return -1;
if (pSctpSession != NULL && pSctpSession->sctpSessionCallbacks.outboundPacketFunc != NULL) {
pSctpSession->sctpSessionCallbacks.outboundPacketFunc(pSctpSession->sctpSessionCallbacks.customData, data, length);
} else {
DLOGE("SCTP attempted to send packet but outboundPacketFunc is not defined");
}

pSctpSession->sctpSessionCallbacks.outboundPacketFunc(pSctpSession->sctpSessionCallbacks.customData, data, length);

return 0;
}

Expand Down
7 changes: 0 additions & 7 deletions src/source/Sctp/Sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ extern "C" {
#define SCTP_ASSOCIATION_DEFAULT_PORT 5000
#define SCTP_DCEP_HEADER_LENGTH 12

#define SCTP_SESSION_ACTIVE 0
#define SCTP_SESSION_SHUTDOWN_INITIATED 1
#define SCTP_SESSION_SHUTDOWN_COMPLETED 2

#define DEFAULT_SCTP_SHUTDOWN_TIMEOUT 2 * HUNDREDS_OF_NANOS_IN_A_SECOND

#define DEFAULT_USRSCTP_TEARDOWN_POLLING_INTERVAL (10 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)

enum {
Expand Down Expand Up @@ -59,7 +53,6 @@ typedef struct {
} SctpSessionCallbacks, *PSctpSessionCallbacks;

typedef struct {
volatile SIZE_T shutdownStatus;
struct socket *socket;
SctpSessionCallbacks sctpSessionCallbacks;
} SctpSession, *PSctpSession;
Expand Down

0 comments on commit 21cffc9

Please sign in to comment.