From b76cb86eaa0aec1d02c5ff29c5a43e1e7a675b27 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Wed, 9 Sep 2009 09:38:41 +0000 Subject: CWS-TOOLING: integrate CWS mhu20 2009-09-01 15:18:43 +0200 mhu r275662 : #i32526# Fixed missing includes, and a wrong cast 2009-08-28 13:30:05 +0200 mhu r275530 : #i32526# Fixed missing includes and remaining merge conflicts. 2009-08-28 13:28:45 +0200 mhu r275529 : #i32526# osl_readLine() now implemented in sal/osl//file.cxx 2009-08-26 19:47:53 +0200 mhu r275445 : CWS-TOOLING: rebase CWS mhu20 to trunk@275331 (milestone: DEV300:m56) 2009-08-25 15:47:00 +0200 mhu r275365 : #i32526# Also maintain phys. file offset. 2009-08-25 15:24:56 +0200 mhu r275364 : #i32526# Added buffered file I/O; refactored file.cxx into multiple files. 2009-08-24 10:38:15 +0200 mhu r275294 : #i32526# Correct OpenFlags for osl_openFile(). 2009-05-25 11:07:34 +0200 mhu r272225 : #i32526# Added support for non-seekable file handles (pipe et al.). 2009-05-25 11:01:50 +0200 mhu r272223 : #i32526# Add osl_readLine() test, cleanup obsolete tests. 2009-05-25 10:56:14 +0200 mhu r272221 : #i32526# Add missing include 2009-05-25 10:48:51 +0200 mhu r272220 : #i32526# Accept OpenJDK (IcedTea6) 1.6.0_0 version string 2009-05-15 19:18:20 +0200 mhu r271965 : #i32526# Initial osl/unx buffered file I/O implementation. 2009-05-15 17:41:57 +0200 mhu r271959 : CWS-TOOLING: rebase CWS mhu20 to trunk@271830 (milestone: DEV300:m48) 2009-03-26 17:28:53 +0100 mhu r270091 : CWS-TOOLING: rebase CWS mhu20 to trunk@270033 (milestone: DEV300:m45) --- sal/workben/makefile.mk | 23 +++- sal/workben/t_layer.c | 314 ----------------------------------------------- sal/workben/t_readline.c | 58 +++++++++ sal/workben/t_tls.c | 257 -------------------------------------- sal/workben/t_zip.c | 183 --------------------------- 5 files changed, 79 insertions(+), 756 deletions(-) delete mode 100644 sal/workben/t_layer.c create mode 100644 sal/workben/t_readline.c delete mode 100644 sal/workben/t_tls.c delete mode 100644 sal/workben/t_zip.c (limited to 'sal/workben') diff --git a/sal/workben/makefile.mk b/sal/workben/makefile.mk index 05afbbb223ea..5f20dd07bd4a 100644 --- a/sal/workben/makefile.mk +++ b/sal/workben/makefile.mk @@ -35,9 +35,10 @@ PRJNAME=sal TARGET=workben LIBTARGET=NO TARGETTYPE=CUI -ENABLE_EXCEPTIONS=TRUE +#ENABLE_EXCEPTIONS=TRUE +NO_DEFAULT_STL=YES -TESTAPP=test_osl_getVolInfo +#TESTAPP=test_osl_getVolInfo #TESTAPP=test_osl_joinProcess #TESTAPP=getlocaleinfotest #TESTAPP=test_osl_joinProcess @@ -45,6 +46,7 @@ TESTAPP=test_osl_getVolInfo #TESTAPP=salstattest #TESTAPP=saldyntest +TESTAPP=t_readline #TESTAPP=t_cipher #TESTAPP=t_digest #TESTAPP=t_random @@ -173,6 +175,23 @@ DEF1EXPORTFILE=export.exp .ENDIF # salstattest +# +# t_readline +# +.IF "$(TESTAPP)" == "t_readline" + +CFILES= t_readline.c +OBJFILES= $(OBJ)$/t_readline.obj + +APP1TARGET= t_readline +APP1OBJS= $(OBJFILES) +APP1STDLIBS=$(SALLIB) +APP1DEPN= $(SLB)$/sal.lib + +APP1RPATH=UREBIN + +.ENDIF # t_readline + # # t_cipher # diff --git a/sal/workben/t_layer.c b/sal/workben/t_layer.c deleted file mode 100644 index 5ceeb7ce21e3..000000000000 --- a/sal/workben/t_layer.c +++ /dev/null @@ -1,314 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_layer.c,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#ifndef _OSL_ISOCKET_H_ -#include -#endif - -/*======================================================================== - * - * osl/debug.c - * - *======================================================================*/ -/* - * __osl_debug_create. - */ -static oslSocketResult SAL_CALL __osl_debug_create ( - oslSocketDescriptor *socket, - oslAddrFamily family, - oslSocketType type, - oslProtocol protocol) -{ - oslSocketResult result; - - if (!(socket->m_lower)) - { - oslSocketDescriptor *lower; - lower = osl_socket_createSocketLayer (osl_socket_getSocketMethods()); - osl_socket_pushSocketLayer (socket, lower); - } - - result = (socket->m_lower->m_methods->m_create)( - socket->m_lower, family, type, protocol); - if (!(result == osl_Socket_Ok)) - return (result); - - if (!(socket->m_private)) - { - /* ... */ - } - return (osl_Socket_Ok); -} - -/* - * __osl_debug_delete. - */ -static void SAL_CALL __osl_debug_delete (oslSocketDescriptor *socket) -{ - if (socket->m_private) - { - /* ... */ - } - if (socket->m_lower) - { - (socket->m_lower->m_methods->m_delete)(socket->m_lower); - osl_socket_deleteSocketLayer (socket->m_lower); - } -} - -/* - * __osl_debug_getOption. - */ -static oslSocketResult SAL_CALL __osl_debug_getOption ( - oslSocketDescriptor *socket, - oslSocketOptionLevel level, - oslSocketOption option, - void *buffer, - sal_uInt32 length) -{ - if (level == osl_Socket_LevelSocketLayer) - { - /* ... */ - return (osl_Socket_Ok); - } - - return (socket->m_lower->m_methods->m_getoption)( - socket->m_lower, level, option, buffer, length); -} - -/* - * __osl_debug_setOption. - */ -static oslSocketResult SAL_CALL __osl_debug_setOption ( - oslSocketDescriptor *socket, - oslSocketOptionLevel level, - oslSocketOption option, - const void *buffer, - sal_uInt32 length) -{ - if (level == osl_Socket_LevelSocketLayer) - { - /* ... */ - return (osl_Socket_Ok); - } - - return (socket->m_lower->m_methods->m_setoption)( - socket->m_lower, level, option, buffer, length); -} - -/* - * __osl_debug_accept. - */ -static oslSocketDescriptor* SAL_CALL __osl_debug_accept ( - oslSocketDescriptor *socket, oslSocketAddr *fromaddr) -{ - oslSocketDescriptor *lower; - lower = (socket->m_lower->m_methods->m_accept)(socket->m_lower, fromaddr); - if (lower) - { - oslSocketDescriptor *upper; - upper = osl_socket_createSocketLayer (socket->m_methods); - osl_socket_pushSocketLayer (upper, lower); - return (upper); - } - return ((oslSocketDescriptor*)NULL); -} - -/* - * __osl_debug_connect. - */ -static oslSocketResult SAL_CALL __osl_debug_connect ( - oslSocketDescriptor *socket, oslSocketAddr addr) -{ - return (socket->m_lower->m_methods->m_connect)(socket->m_lower, addr); -} - -/* - * __osl_debug_close. - */ -static void SAL_CALL __osl_debug_close (oslSocketDescriptor *socket) -{ - (socket->m_lower->m_methods->m_close)(socket->m_lower); -} - -/* - * __osl_shutdown. - */ -static void SAL_CALL __osl_debug_shutdown ( - oslSocketDescriptor *socket, oslSocketDirection direction) -{ - (socket->m_lower->m_methods->m_shutdown)(socket->m_lower, direction); -} - -/* - * __osl_debug_methods. - */ -static oslSocketMethods __osl_debug_methods = -{ - NULL /* initialized on demand */ -}; - -/* - * osl_debug_getSocketMethods. - */ -const oslSocketMethods* SAL_CALL osl_debug_getSocketMethods (void) -{ - static oslInterlockedCount nonce = 0; - if (osl_incrementInterlockedCount (&nonce) == 1) - { - const oslSocketMethods *methods = osl_socket_getDefaultSocketMethods(); - __osl_debug_methods = *methods; - - __osl_debug_methods.m_create = __osl_debug_create; - __osl_debug_methods.m_delete = __osl_debug_delete; - - __osl_debug_methods.m_getoption = __osl_debug_getOption; - __osl_debug_methods.m_setoption = __osl_debug_setOption; - - __osl_debug_methods.m_accept = __osl_debug_accept; - __osl_debug_methods.m_connect = __osl_debug_connect; - __osl_debug_methods.m_close = __osl_debug_close; - - __osl_debug_methods.m_shutdown = __osl_debug_shutdown; - - osl_incrementInterlockedCount (&nonce); - } - - osl_decrementInterlockedCount (&nonce); - return (&__osl_debug_methods); -} - -/*======================================================================== - * - * osl/socket.c (physical, bottom layer). - * - *======================================================================*/ -#if 0 /* NYI */ - -static oslSocketResult SAL_CALL __osl_socket_create ( - oslSocketDescriptor *socket, - oslAddrFamily family, - oslSocketType type, - oslProtocol protocol) -{ -#if OSL_DEBUG_LEVEL > 1 - const oslSocketMethods *debug = osl_debug_getSocketMethods(); - if (!(socket->m_upper || socket->m_upper->m_methods == debug)) - { - oslSocketDescriptor *upper; - - upper = osl_socket_createSocketLayer (debug); - osl_socket_pushSocketLayer (upper, socket); - - return (upper->m_methods->m_create)(upper, family, type, protocol); - } -#endif /* OSL_DEBUG_LEVEL */ - if (!(socket->m_private)) - { - /* ... */ - socket->m_private = osl_createSocket (family, type, protocol); - } - return (osl_Socket_Ok); -} - -#endif /* NYI */ - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - oslSocketDescriptor *socket; - - socket = osl_socket_createSocketLayer (osl_debug_getSocketMethods()); - if (socket) - { - oslSocketDescriptor *connection; - oslSocketResult result; - oslSocketAddr addr, from; - sal_Int32 option = 1; - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_bind (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - osl_socket_delete (connection); - - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_close (socket); - osl_socket_delete (socket); - - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - diff --git a/sal/workben/t_readline.c b/sal/workben/t_readline.c new file mode 100644 index 000000000000..9cbc7d39cf20 --- /dev/null +++ b/sal/workben/t_readline.c @@ -0,0 +1,58 @@ +/* + * t_readline.c + */ + +#include "osl/file.h" + +#include "osl/diagnose.h" +#include "rtl/ustring.h" +#include "rtl/byteseq.h" + +#include + +/* main */ +int main (int argc, char ** argv) +{ + if (argc > 1) + { + oslFileError result; + oslFileHandle hFile = 0; + + rtl_uString * pSystemPath = 0; + rtl_uString * pFileUrl = 0; + + rtl_uString_newFromAscii (&pSystemPath, argv[1]); + + result = osl_getFileURLFromSystemPath (pSystemPath, &pFileUrl); + rtl_uString_release (pSystemPath), pSystemPath = 0; + if (result != osl_File_E_None) + return (result); + + result = osl_openFile (pFileUrl, &hFile, osl_File_OpenFlag_Read); + rtl_uString_release (pFileUrl), pFileUrl = 0; + if (result == osl_File_E_None) + { + sal_Sequence * pBuffer = 0; + for ( ;; ) + { + sal_Int32 i, n; + + result = osl_readLine (hFile, &pBuffer); + if (result != osl_File_E_None) + break; +#if 0 + if (pBuffer->elements[0] == 0) + /* @@@ cannot distinguish empty line from EOF @@@ */ + break; +#endif + for (i = 0, n = pBuffer->nElements; i < n; i++) + printf ("%c", (char)(pBuffer->elements[i])); + printf("\n"); + } + + rtl_byte_sequence_release (pBuffer), pBuffer = 0; + (void) osl_closeFile (hFile); + } + } + return 0; +} diff --git a/sal/workben/t_tls.c b/sal/workben/t_tls.c deleted file mode 100644 index 2f82bee0a11f..000000000000 --- a/sal/workben/t_tls.c +++ /dev/null @@ -1,257 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_tls.c,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#include -#include -#ifndef _OSL_ISOCKET_H_ -#include -#endif - -#ifndef _OSL_TLS_H_ -#include -#endif - -#include -#include - -/*======================================================================== - * - * Internals. - * - *======================================================================*/ -void SAL_CALL __rtl_sequence_release (sal_Sequence *value) -{ - if (value) - { - if (osl_decrementInterlockedCount (&(value->nRefCount)) == 0) - rtl_freeMemory (value); - } -} - -void SAL_CALL __rtl_sequence_new (sal_Sequence **value, sal_Int32 length) -{ - if (value) - { - __rtl_sequence_release (*value); - - *value = (sal_Sequence*)rtl_allocateMemory ( - SAL_SEQUENCE_HEADER_SIZE + length); - - (*value)->nRefCount = 1; - (*value)->nElements = 0; - } -} - -void load_sequence (sal_Sequence **ppSequence, const sal_Char *name) -{ - oslFileError result; - rtl_uString *pName, *pPath; - - if (ppSequence) - { - __rtl_sequence_release (*ppSequence); - *ppSequence = NULL; - } - - pName = NULL; - rtl_uString_newFromAscii (&pName, name); - - pPath = NULL; - result = osl_searchNormalizedPath (pName, NULL, &pPath); - if (result == osl_File_E_None) - { - oslFileHandle hFile; - - result = osl_openFile (pPath, &hFile, osl_File_OpenFlag_Read); - if (result == osl_File_E_None) - { - sal_uInt64 nSize = 0, nRead = 0; - - osl_setFilePos (hFile, osl_Pos_End, 0); - osl_getFilePos (hFile, &nSize); - osl_setFilePos (hFile, osl_Pos_Absolut, 0); - - __rtl_sequence_new (ppSequence, (sal_Int32)nSize); - - osl_readFile (hFile, (*ppSequence)->elements, nSize, &nRead); - (*ppSequence)->nElements = (sal_Int32)nRead; - } - osl_closeFile (hFile); - - rtl_uString_release (pPath); - } - - rtl_uString_release (pName); -} - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - static const sal_Char p[] = "GET / HTTP/1.0\015\012\015\012"; - oslSocketDescriptor *socket; - - - socket = osl_socket_createSocketLayer (osl_tls_getSocketMethods()); - if (socket) - { - oslSocketAddr target; - oslSocketResult result; - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - rtl_uString *dotted = NULL; - - - rtl_uString_newFromAscii (&dotted, argv[1]); - target = osl_createInetSocketAddr (dotted, 443); - rtl_uString_release (dotted); - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect (socket, target); - osl_destroySocketAddr (target); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect_handshake (socket, target); - OSL_ASSERT(result == osl_Socket_Ok); - - if (osl_socket_send (socket, p, strlen(p), flag) > 0) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - - while ((k = osl_socket_recv (socket, buffer, n, flag)) > 0) - fwrite (buffer, 1, k, stdout); - } - - osl_socket_shutdown (socket, osl_Socket_DirReadWrite); - osl_socket_close (socket); - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - - socket = osl_socket_createSocketLayer (osl_tls_getSocketMethods()); - if (socket) - { - oslSocketDescriptor *connection; - oslSocketResult result; - oslSocketAddr addr, from; - sal_Int32 option = 1; - sal_Sequence *data = NULL; - - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_bind (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - load_sequence (&data, "s_cert.der"); - if (data && data->nElements) - { - result = osl_socket_setOption ( - socket, - osl_Socket_LevelTLS, - osl_Socket_OptionCertificate, - data->elements, data->nElements); - OSL_ASSERT(result == osl_Socket_Ok); - } - - load_sequence (&data, "s_pkey.der"); - if (data && data->nElements) - { - result = osl_socket_setOption ( - socket, - osl_Socket_LevelTLS, - osl_Socket_OptionPrivateKey, - data->elements, data->nElements); - OSL_ASSERT(result == osl_Socket_Ok); - } - __rtl_sequence_release (data); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - result = osl_socket_accept_handshake (connection, from); - OSL_ASSERT(result == osl_Socket_Ok); - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - - osl_socket_delete (connection); - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - diff --git a/sal/workben/t_zip.c b/sal/workben/t_zip.c deleted file mode 100644 index 42bb819f0256..000000000000 --- a/sal/workben/t_zip.c +++ /dev/null @@ -1,183 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_zip.c,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#ifndef _OSL_ZSOCKET_H_ -#include -#endif - -#include - -/*======================================================================== - * - * internals. - * - *======================================================================*/ -void SAL_CALL clientSocketReader (void *pData) -{ - oslSocketDescriptor *socket; - - socket = (oslSocketDescriptor*)pData; - if (socket) - { - sal_Char buffer[128]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - while ((k = osl_socket_recv (socket, buffer, n, flag)) > 0) - { - fwrite (buffer, 1, k, stdout); - fflush (stdout); - } - } -} - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - oslSocketDescriptor *socket; - - socket = osl_socket_createSocketLayer (osl_zlib_getSocketMethods()); - if (socket) - { - oslSocketAddr addr = 0; - oslSocketResult result; - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - if (argc > 1) - { - rtl_uString *host = 0; - - rtl_uString_newFromAscii (&host, argv[1]); - addr = osl_resolveHostname (host); - rtl_uString_release (host); - } - - if (addr) - { - sal_Char buffer[128]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - oslThread reader; - - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_connect (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect_handshake (socket, addr); - osl_destroySocketAddr (addr); - OSL_ASSERT(result == osl_Socket_Ok); - - reader = osl_createSuspendedThread (clientSocketReader, socket); - OSL_ASSERT(reader); - osl_resumeThread (reader); - - while ((k = fread (buffer, 1, n, stdin)) > 0) - { - if (osl_socket_send (socket, buffer, k, flag) < 0) - break; - } - - osl_socket_shutdown (socket, osl_Socket_DirReadWrite); - osl_socket_close (socket); - - osl_joinWithThread (reader); - osl_destroyThread (reader); - } - else - { - oslSocketDescriptor *connection; - oslSocketAddr from = 0; - sal_Int32 option = 1; - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_bind (socket, addr); - osl_destroySocketAddr (addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[64]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - result = osl_socket_accept_handshake (connection, from); - osl_destroySocketAddr (from); - OSL_ASSERT(result == osl_Socket_Ok); - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - - osl_socket_delete (connection); - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_close (socket); - } - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - -- cgit v1.2.3