diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2218160c9f..c689af49bb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,37 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-19 17:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbnetio/netiomt.prg + + added 8-th parameter to NETIO_MTSERVER(). + It allows to set own server function which can be used for + statistic or connection INIT/EXIT code. By default it's + @netio_server() is used. + User functions may look like: + function custom_netio_server( pConnectionSocket ) + register_connection( pConnectionSocket ) + begin sequence + netio_server( pConnectionSocket ) + finally + unregister_connection( pConnectionSocket ) + end sequence + return nil + + * harbour/contrib/hbnetio/netiosrv.c + + added new server function + NETIO_SRVSOCKET( ) -> + can be used with Harbour socket functions (hb_socket*()) + Please remember that handle can be used only for statistics + and must not be used for any send/receive operations. + + * harbour/contrib/hbnetio/readme.txt + * updated + + * harbour/contrib/hbwin/tests/olesrv1.prg + * modified to return HVM error object as OLE object to the client + on RTE + + 2011-01-19 07:21 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbexpra.c ! fixed casting for C++ mode diff --git a/harbour/contrib/hbnetio/netiomt.prg b/harbour/contrib/hbnetio/netiomt.prg index 85263a6f96..f39d0c39cf 100644 --- a/harbour/contrib/hbnetio/netiomt.prg +++ b/harbour/contrib/hbnetio/netiomt.prg @@ -8,8 +8,9 @@ * very simple TCP/IP file server with RPC support * All files which names starts 'net:' are redirected to this API. * This is code for simple MT server which is activated by: - * NETIO_MTSERVER( [], [], [], [], - * [], [], [] ) + * NETIO_MTSERVER( [], [], [], [], + * [], [], [], + * [] ) * -> | NIL * and can be stopped by: * NETIO_SERVERSTOP( , .T. ) @@ -60,10 +61,16 @@ #include "error.ch" -FUNCTION NETIO_MTSERVER( nPort, cIfAddr, cRootDir, xRPC, ... ) +FUNCTION NETIO_MTSERVER( nPort, cIfAddr, cRootDir, xRPC, ; + cPasswd, nCompressLevel, nStrategy, ; + sSrvFunc ) LOCAL pListenSocket, lRPC LOCAL oError + IF sSrvFunc == NIL + sSrvFunc := @netio_server() + ENDIF + IF hb_mtvm() SWITCH ValType( xRPC ) CASE "S" @@ -72,12 +79,15 @@ FUNCTION NETIO_MTSERVER( nPort, cIfAddr, cRootDir, xRPC, ... ) EXIT CASE "L" lRPC := xRPC + EXIT OTHERWISE xRPC := NIL ENDSWITCH pListenSocket := netio_listen( nPort, cIfAddr, cRootDir, lRPC ) IF !Empty( pListenSocket ) - hb_threadDetach( hb_threadStart( @netio_srvloop(), pListenSocket, xRPC, ... ) ) + hb_threadDetach( hb_threadStart( @netio_srvloop(), pListenSocket, ; + xRPC, sSrvFunc, ; + cPasswd, nCompressLevel, nStrategy ) ) ENDIF ELSE oError := ErrorNew() @@ -96,7 +106,8 @@ FUNCTION NETIO_MTSERVER( nPort, cIfAddr, cRootDir, xRPC, ... ) ENDIF RETURN pListenSocket -STATIC FUNCTION NETIO_SRVLOOP( pListenSocket, xRPC, ... ) + +STATIC FUNCTION NETIO_SRVLOOP( pListenSocket, xRPC, sSrvFunc, ... ) LOCAL pConnectionSocket WHILE .T. @@ -107,7 +118,7 @@ STATIC FUNCTION NETIO_SRVLOOP( pListenSocket, xRPC, ... ) IF xRPC != NIL netio_rpcfilter( pConnectionSocket, xRPC ) ENDIF - hb_threadDetach( hb_threadStart( @netio_server(), pConnectionSocket ) ) + hb_threadDetach( hb_threadStart( sSrvFunc, pConnectionSocket ) ) pConnectionSocket := NIL ENDDO RETURN NIL diff --git a/harbour/contrib/hbnetio/netiosrv.c b/harbour/contrib/hbnetio/netiosrv.c index 7d40439758..7123e05b6e 100644 --- a/harbour/contrib/hbnetio/netiosrv.c +++ b/harbour/contrib/hbnetio/netiosrv.c @@ -1379,3 +1379,11 @@ HB_FUNC( NETIO_SRVSTATUS ) } hb_retni( iStatus ); } + +HB_FUNC( NETIO_SRVSOCKET ) +{ + PHB_CONSRV conn = s_consrvParam( 1 ); + + if( conn ) + hb_socketItemPut( hb_stackReturnItem(), conn->sd ); +} diff --git a/harbour/contrib/hbnetio/readme.txt b/harbour/contrib/hbnetio/readme.txt index a747ad23ca..8d75edf32c 100644 --- a/harbour/contrib/hbnetio/readme.txt +++ b/harbour/contrib/hbnetio/readme.txt @@ -146,10 +146,16 @@ Server side functions: | | NIL ) -> NIL NETIO_SERVERSTOP( | [, ] ) -> NIL NETIO_MTSERVER( [], [], [], - [ | | ], - [], [], [] ) + [ | | ], + [], [], [], + [] ) -> NETIO_SRVSTATUS( [, ] ) -> NETIO_SRVSENDITEM( , , ) -> NETIO_SRVSENDDATA( , , ) -> + + NETIO_SRVSOCKET( ) -> + can be used with Harbour socket functions (hb_socket*()) + Please remember that handle can be used only for statistics + and must not be used for any send/receive operations. diff --git a/harbour/contrib/hbwin/tests/olesrv1.prg b/harbour/contrib/hbwin/tests/olesrv1.prg index 2b225b9caf..59886c1e39 100644 --- a/harbour/contrib/hbwin/tests/olesrv1.prg +++ b/harbour/contrib/hbwin/tests/olesrv1.prg @@ -123,25 +123,38 @@ EXPORTED: ENDCLASS METHOD Eval( cMethodName, ... ) CLASS OleNetioSrv + LOCAL xRetVal, oErr - SWITCH cMethodName - CASE "CONNECT" - RETURN !Empty( ::pConn := NETIO_GETCONNECTION( ... ) ) - CASE "DISCONNECT" - ::pConn := NIL - RETURN .T. - CASE "PROCEXISTS" - RETURN NETIO_PROCEXISTS( ::pConn, ... ) - CASE "PROCEXEC" - RETURN NETIO_PROCEXEC( ::pConn, ... ) - CASE "PROCEXECW" - RETURN NETIO_PROCEXECW( ::pConn, ... ) - CASE "FUNCEXEC" - RETURN NETIO_FUNCEXEC( ::pConn, ... ) - ENDSWITCH + BEGIN SEQUENCE WITH { |oErr| BREAK( oErr ) } + SWITCH cMethodName + CASE "CONNECT" + xRetVal := !Empty( ::pConn := NETIO_GETCONNECTION( ... ) ) + EXIT + CASE "DISCONNECT" + ::pConn := NIL + xRetVal := .T. + EXIT + CASE "PROCEXISTS" + xRetVal := NETIO_PROCEXISTS( ::pConn, ... ) + EXIT + CASE "PROCEXEC" + xRetVal := NETIO_PROCEXEC( ::pConn, ... ) + EXIT + CASE "PROCEXECW" + xRetVal := NETIO_PROCEXECW( ::pConn, ... ) + EXIT + CASE "FUNCEXEC" + xRetVal := NETIO_FUNCEXEC( ::pConn, ... ) + EXIT + OTHERWISE + /* redirect all other messages to RPC server as function calls */ + xRetVal := NETIO_FUNCEXEC( ::pConn, cMethodName, ... ) + ENDSWITCH + RECOVER USING oErr + xRetVal := oErr + END SEQUENCE -/* redirect all other messages to RPC server as function calls */ -RETURN NETIO_FUNCEXEC( ::pConn, cMethodName, ... ) +RETURN xRetVal ANNOUNCE GT_SYS