From ad021a1d1852f80da3290d7a96b81731046d8b0d Mon Sep 17 00:00:00 2001
From: "Bill Ryan (PC)" <ryan.william@mayo.edu>
Date: Wed, 1 Apr 2015 13:47:38 -0500
Subject: [PATCH] Allow the user to modify the socket timeout value from a
 command line option.

---
 dcmnet/apps/storescp.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/dcmnet/apps/storescp.cc b/dcmnet/apps/storescp.cc
index d897c16..f3f3a92 100644
--- a/dcmnet/apps/storescp.cc
+++ b/dcmnet/apps/storescp.cc
@@ -65,6 +65,8 @@ END_EXTERN_C
 #include "dcmtk/dcmdata/dcuid.h"        /* for dcmtk version name */
 #include "dcmtk/dcmdata/dcdeftag.h"
 #include "dcmtk/dcmdata/dcostrmz.h"     /* for dcmZlibCompressionLevel */
+#include "dcmtk/dcmnet/dcmtrans.h"
+
 
 #ifdef WITH_OPENSSL
 #include "dcmtk/dcmtls/tlstrans.h"
@@ -179,6 +181,7 @@ static const char *opt_profileName = NULL;
 T_DIMSE_BlockingMode opt_blockMode = DIMSE_BLOCKING;
 int                opt_dimse_timeout = 0;
 int                opt_acse_timeout = 30;
+int                opt_socket_timeout = 60;
 
 #if defined(HAVE_FORK) || defined(_WIN32)
 OFBool             opt_forkMode = OFFalse;
@@ -306,6 +309,7 @@ int main(int argc, char *argv[])
 
       cmd.addOption("--acse-timeout",           "-ta",  1, "[s]econds: integer (default: 30)", "timeout for ACSE messages");
       cmd.addOption("--dimse-timeout",          "-td",  1, "[s]econds: integer (default: unlimited)", "timeout for DIMSE messages");
+	  cmd.addOption("--socket-timeout",         "-ts",  1, "[s]econds: integer (default: 60)", "timeout for underlying socket");
 
       OFString opt1 = "set my AE title (default: ";
       opt1 += APPLICATIONTITLE;
@@ -579,6 +583,12 @@ int main(int argc, char *argv[])
       opt_dimse_timeout = OFstatic_cast(int, opt_timeout);
       opt_blockMode = DIMSE_NONBLOCKING;
     }
+	if (cmd.findOption("--socket-timeout"))
+	{
+		OFCmdSignedInt opt_timeout = 0;
+		app.checkValue(cmd.getValueAndCheckMin(opt_timeout, 1));
+		opt_socket_timeout = OFstatic_cast(int, opt_timeout);
+	}
 
     if (cmd.findOption("--aetitle")) app.checkValue(cmd.getValue(opt_respondingAETitle));
     if (cmd.findOption("--max-pdu")) app.checkValue(cmd.getValueAndCheckMinMax(opt_maxPDU, ASC_MINIMUMPDUSIZE, ASC_MAXIMUMPDUSIZE));
@@ -1225,6 +1235,9 @@ static OFCondition acceptAssociation(T_ASC_Network *net, DcmAssociationConfigura
   const char* transferSyntaxes[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
   int numTransferSyntaxes = 0;
 
+  // Set the socket timeout value
+  DcmTransportConnection::setSocketTimeout(opt_socket_timeout);
+
   // try to receive an association. Here we either want to use blocking or
   // non-blocking, depending on if the option --eostudy-timeout is set.
   if( opt_endOfStudyTimeout == -1 )
-- 
1.8.3.msysgit.0

From 5f7668a6fd3c46c4917514e8df794be7b3b243dd Mon Sep 17 00:00:00 2001
From: "Bill Ryan (PC)" <ryan.william@mayo.edu>
Date: Wed, 1 Apr 2015 13:41:29 -0500
Subject: [PATCH] Added Socket timeout value to the DCMTransportConnection
 class

---
 dcmnet/include/dcmtk/dcmnet/dcmtrans.h | 15 +++++++++++++++
 dcmnet/libsrc/dcmtrans.cc              | 10 ++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/dcmnet/include/dcmtk/dcmnet/dcmtrans.h b/dcmnet/include/dcmtk/dcmnet/dcmtrans.h
index 54da8fb..9586280 100644
--- a/dcmnet/include/dcmtk/dcmnet/dcmtrans.h
+++ b/dcmnet/include/dcmtk/dcmnet/dcmtrans.h
@@ -157,6 +157,17 @@ public:
    */
   static OFBool selectReadableAssociation(DcmTransportConnection *connections[], int connCount, int timeout);
 
+
+  /** returns the socket timeout value in seconds
+  *  @return socket timeout value
+  */
+  static int getSocketTimeout() { return socketTimeout; }
+
+  /** set the socket file descriptor managed by this object.
+  *  @param socket file descriptor
+  */
+  static void setSocketTimeout(int timeout) { socketTimeout = timeout; }
+
 protected:
 
   /** returns the socket file descriptor managed by this object.
@@ -213,6 +224,10 @@ private:
    */
   static OFBool fastSelectReadableAssociation(DcmTransportConnection *connections[], int connCount, int timeout);
 
+  /** Create a class value for how long to hold onto a connection before aborting
+  */
+  static int socketTimeout;
+
   /// the socket file descriptor used by the transport connection.
   int theSocket;
 };
diff --git a/dcmnet/libsrc/dcmtrans.cc b/dcmnet/libsrc/dcmtrans.cc
index 892bd57..a4fbe74 100644
--- a/dcmnet/libsrc/dcmtrans.cc
+++ b/dcmnet/libsrc/dcmtrans.cc
@@ -53,6 +53,8 @@ END_EXTERN_C
 #include <GUSI.h>	/* Use the Grand Unified Sockets Interface (GUSI) on Macintosh */
 #endif
 
+int DcmTransportConnection::socketTimeout = 60;
+
 DcmTransportConnection::DcmTransportConnection(int openSocket)
 : theSocket(openSocket)
 {
@@ -61,8 +63,8 @@ DcmTransportConnection::DcmTransportConnection(int openSocket)
   {
 #ifndef DISABLE_SEND_TIMEOUT
     {
-      /* use a timeout of 60 seconds for the send() function */
-      const int sendTimeout = 60;
+      /* set a timeout for the send() function */
+		const int sendTimeout = DcmTransportConnection::socketTimeout;
       DCMNET_DEBUG("setting network send timeout to " << sendTimeout << " seconds");
 #ifdef HAVE_WINSOCK_H
       // for Windows, specify send timeout in milliseconds
@@ -85,8 +87,8 @@ DcmTransportConnection::DcmTransportConnection(int openSocket)
 #endif
 #ifndef DISABLE_RECV_TIMEOUT
     {
-      /* use a timeout of 60 seconds for the recv() function */
-      const int recvTimeout = 60;
+      /* set a timeout for the recv() function */
+	  const int recvTimeout = socketTimeout;
       DCMNET_DEBUG("setting network receive timeout to " << recvTimeout << " seconds");
 #ifdef HAVE_WINSOCK_H
       // for Windows, specify receive timeout in milliseconds
-- 
1.8.3.msysgit.0

