From c731995d0618a84a51de3c0a8e8420453e2ea501 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Jan 2011 17:08:30 +0000 Subject: [PATCH] 2011-01-26 18:06 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbnetio/utils/netiosrv/netiosrv.prg * contrib/hbnetio/utils/netiosrv/netiocmd.prg + Help text now show port and iface defaults. + Client info is now stored in the connection table (not used anywhere ATM). Finally solved it by using thread ID to identify connections in RPC server side. + Added thread ID to the per connection data structure. + 'show' command now shows thread ID instead of ordinal. --- harbour/ChangeLog | 11 +++++ .../hbnetio/utils/netiosrv/netiocmd.prg | 2 +- .../hbnetio/utils/netiosrv/netiosrv.prg | 44 ++++++++++++++----- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b9cc74ea2c..d3061c4a62 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,16 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-26 18:06 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbnetio/utils/netiosrv/netiosrv.prg + * contrib/hbnetio/utils/netiosrv/netiocmd.prg + + Help text now show port and iface defaults. + + Client info is now stored in the connection + table (not used anywhere ATM). Finally solved it by + using thread ID to identify connections in RPC server side. + + Added thread ID to the per connection data structure. + + 'show' command now shows thread ID instead of ordinal. + 2011-01-26 13:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbnetio/utils/netiosrv/netiosrv.prg * contrib/hbnetio/utils/netiosrv/netiocmd.prg @@ -29,6 +39,7 @@ server console. ; QUESTION: How to find out in an RPC call on the server side, which connection it belongs to? + [DONE: Using the thread ID] ; QUESTION: Should NETIO_DISCONNECT() support optional pConnection parameter (instead of IP/port pair)? diff --git a/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg b/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg index caf07c9a7a..ad756c0b09 100644 --- a/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg +++ b/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg @@ -246,7 +246,7 @@ STATIC PROCEDURE cmdConnInfo( pConnection ) QQOut( "Number of connections: " + hb_ntos( Len( aArray ) ), hb_eol() ) FOR EACH hConn IN aArray - QQOut( "#" + hb_ntos( hConn:__enumIndex() ) + " " +; + QQOut( "#" + PadR( hb_ntos( hConn[ "nThreadID" ] ), Len( Str( hConn[ "nThreadID" ] ) ) ) + " " +; hb_TToC( hConn[ "tStart" ], "YYYY.MM.DD", "HH:MM:SS" ) + " " +; PadR( hConn[ "cStatus" ], 12 ) + " " +; "fcnt: " + Str( hConn[ "nFilesCount" ] ) + " " +; diff --git a/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg b/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg index b7e3571eb3..b61d6e6ddd 100644 --- a/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg +++ b/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg @@ -54,9 +54,10 @@ REQUEST HB_MT #define _NETIOSRV_MAX_ 14 #define _NETIOSRV_CONN_pConnection 1 -#define _NETIOSRV_CONN_tStart 2 -#define _NETIOSRV_CONN_hInfo 3 -#define _NETIOSRV_CONN_MAX_ 3 +#define _NETIOSRV_CONN_nThreadID 2 +#define _NETIOSRV_CONN_tStart 3 +#define _NETIOSRV_CONN_hInfo 4 +#define _NETIOSRV_CONN_MAX_ 4 PROCEDURE Main( ... ) LOCAL netiosrv[ _NETIOSRV_MAX_ ] @@ -268,6 +269,7 @@ STATIC PROCEDURE netiosrv_conn_register( netiosrv, pConnectionSocket ) LOCAL nconn[ _NETIOSRV_CONN_MAX_ ] nconn[ _NETIOSRV_CONN_pConnection ] := pConnectionSocket + nconn[ _NETIOSRV_CONN_nThreadID ] := hb_threadID() nconn[ _NETIOSRV_CONN_tStart ] := hb_DateTime() hb_mutexLock( netiosrv[ _NETIOSRV_mtxConnection ] ) @@ -294,18 +296,33 @@ STATIC PROCEDURE netiosrv_conn_unregister( netiosrv, pConnectionSocket ) /* RPC management interface */ -STATIC FUNCTION netio_mgmt_rpc_clientinfo( netiomgm, hInfo ) +STATIC FUNCTION netio_mgmt_rpc_clientinfo( netiosrv, hInfo ) + LOCAL nconn +#if 0 LOCAL h +#endif - HB_SYMBOL_UNUSED( netiomgm ) + IF hb_isHash( hInfo ) - /* QUESTION: How to find out which connection has sent this RPC request? [vszakats] */ +#if 0 + IF ! Empty( hInfo ) + QQOut( "Management client information:", hb_eol() ) + FOR EACH h IN hInfo + QQOut( h:__enumKey(), h, hb_eol() ) + NEXT + ENDIF +#endif - IF hb_isHash( hInfo ) .AND. ! Empty( hInfo ) - QQOut( "Management client information:", hb_eol() ) - FOR EACH h IN hInfo - QQOut( h:__enumKey(), h, hb_eol() ) + hb_mutexLock( netiosrv[ _NETIOSRV_mtxConnection ] ) + + FOR EACH nconn IN netiosrv[ _NETIOSRV_hConnection ] + IF nconn[ _NETIOSRV_CONN_nThreadID ] == hb_threadID() + nconn[ _NETIOSRV_CONN_hInfo ] := hInfo + EXIT + ENDIF NEXT + + hb_mutexUnlock( netiosrv[ _NETIOSRV_mtxConnection ] ) ENDIF RETURN NIL @@ -398,6 +415,7 @@ STATIC FUNCTION netio_mgmt_rpc_conninfo( netiosrv ) netio_srvStatus( nconn[ _NETIOSRV_CONN_pConnection ], NETIO_SRVINFO_PEERADDRESS , @aAddressPeer ) AAdd( aArray, {; + "nThreadID" => nconn[ _NETIOSRV_CONN_nThreadID ],; "tStart" => nconn[ _NETIOSRV_CONN_tStart ],; "cStatus" => ConnStatusStr( nStatus ),; "nFilesCount" => nFilesCount,; @@ -486,8 +504,9 @@ STATIC PROCEDURE HB_Usage() OutStd( hb_eol() ) OutStd( "Options:" , hb_eol() ) OutStd( hb_eol() ) - OutStd( " -port= accept incoming connections on IP port " , hb_eol() ) + OutStd( " -port= accept incoming connections on IP port . Default: 2941" , hb_eol() ) OutStd( " -iface= accept incoming connections on IPv4 interface " , hb_eol() ) + OutStd( " Default: all" , hb_eol() ) OutStd( " -rootdir= use as root directory for served file system" , hb_eol() ) OutStd( " -rpc accept RPC requests" , hb_eol() ) OutStd( " -rpc= set RPC processor .hrb module to " , hb_eol() ) @@ -497,8 +516,9 @@ STATIC PROCEDURE HB_Usage() OutStd( hb_eol() ) OutStd( " -noui don't open interactive console" , hb_eol() ) OutStd( hb_eol() ) - OutStd( " -adminport= accept management connections on IP port " , hb_eol() ) + OutStd( " -adminport= accept management connections on IP port . Default: 2940" , hb_eol() ) OutStd( " -adminiface= accept manegement connections on IPv4 interface " , hb_eol() ) + OutStd( " Default: 127.0.0.1" , hb_eol() ) OutStd( " -adminpass= set remote management password" , hb_eol() ) OutStd( hb_eol() ) OutStd( " --version display version header only" , hb_eol() )