Added support for TCP client sockets. Fixed various bugs in the argument parsing code. Added stdout and stderr printf clients.

git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@1033 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
ahodgkinson
2007-02-20 20:04:56 +00:00
parent 2cdd19daef
commit 49ac1a0e4f
5 changed files with 1893 additions and 1819 deletions

View File

@@ -684,6 +684,7 @@
flminterface IF_ThreadInfo;
flminterface IF_OStream;
flminterface IF_IOStream;
flminterface IF_TCPListener;
flminterface IF_SSLIOStream;
flminterface IF_LogMessageClient;
flminterface IF_Thread;
@@ -696,6 +697,7 @@
class F_ListItem;
class F_ListManager;
class F_Arg;
class F_TCPIOStream;
/****************************************************************************
Desc: Cross-platform definitions
@@ -1529,8 +1531,14 @@
const char * pszHost,
FLMUINT uiPort,
FLMUINT uiFlags,
FLMUINT uiConnectTimeout,
IF_IOStream ** ppIOStream);
RCODE FLMAPI FlmOpenTCPListener(
FLMBYTE * pucBindAddr,
FLMUINT uiBindPort,
IF_TCPListener ** ppListener);
RCODE FLMAPI FlmRemoveMultiFileStream(
const char * pszDirectory,
const char * pszBaseName);
@@ -1624,6 +1632,52 @@
#endif
};
/****************************************************************************
Desc:
****************************************************************************/
flminterface IF_TCPListener : public F_Object
{
virtual RCODE FLMAPI connectClient(
F_TCPIOStream ** ppClientStream,
FLMUINT uiTimeout = 0);
};
/****************************************************************************
Desc:
****************************************************************************/
flminterface IF_TCPIOStream : public IF_IOStream
{
virtual RCODE FLMAPI read(
void * pvBuffer,
FLMUINT uiBytesToRead,
FLMUINT * puiBytesRead) = 0;
virtual RCODE FLMAPI write(
const void * pvBuffer,
FLMUINT uiBytesToWrite,
FLMUINT * puiBytesWritten) = 0;
virtual const char * FLMAPI getLocalHostName( void) = 0;
virtual const char * FLMAPI getLocalHostAddress( void) = 0;
virtual const char * FLMAPI getPeerHostName( void) = 0;
virtual const char * FLMAPI getPeerHostAddress( void) = 0;
virtual RCODE FLMAPI readNoWait(
void * pvBuffer,
FLMUINT uiCount,
FLMUINT * puiReadRead) = 0;
virtual RCODE FLMAPI readAll(
void * pvBuffer,
FLMUINT uiCount,
FLMUINT * puiBytesRead) = 0;
virtual RCODE FLMAPI closeStream( void) = 0;
};
/****************************************************************************
Desc:
****************************************************************************/
@@ -3979,6 +4033,10 @@
const char * pszFormat,
...);
FLMINT FLMAPI f_errprintf(
const char * pszFormat,
...);
FLMINT FLMAPI f_printf(
IF_PrintfClient * pClient,
const char * pszFormat,
@@ -4141,6 +4199,12 @@
FLMUINT uiFlags) = 0;
};
RCODE FLMAPI FlmAllocStdoutPrintfClient(
IF_PrintfClient ** ppClient);
RCODE FLMAPI FlmAllocStderrPrintfClient(
IF_PrintfClient ** ppClient);
/****************************************************************************
Desc: XML
****************************************************************************/
@@ -7321,12 +7385,8 @@
typedef FLMBOOL (* F_ARG_VALIDATOR) (
const char * pszGivenArg,
const char * pszIdentifier,
F_StringAcc * pOutputAccumulator,
void * pvUserData);
typedef void (* F_ARG_OUTPUT_CALLBACK) (
const char * pszOutputString,
void * pvUserData);
IF_PrintfClient * pPrintfClient,
void * pvAppData);
typedef enum
{
@@ -7352,18 +7412,13 @@
{
public:
F_ArgSet(
char * pszDescription,
F_ARG_OUTPUT_CALLBACK outputCallback,
void * pvOutputCallbackData);
F_ArgSet();
virtual ~F_ArgSet();
FINLINE const char * FLMAPI getDescription( void)
{
return( m_pszDescription);
}
RCODE FLMAPI setup(
IF_PrintfClient * pPrintfClient);
RCODE FLMAPI addArg(
const char * pszIdentifier,
const char * pszShortHelp,
@@ -7374,8 +7429,7 @@
RCODE FLMAPI parseCommandLine(
FLMUINT uiArgc,
const char ** ppszArgv,
FLMBOOL * pbPrintedUsage);
const char ** ppszArgv);
FLMBOOL FLMAPI argIsPresent(
const char * pszIdentifier);
@@ -7421,15 +7475,12 @@
F_Arg * getArg(
const char * pszIdentifier);
RCODE printUsage( void);
void printUsage( void);
RCODE dump(
void dump(
F_Vector * pVec,
FLMUINT uiVecLen);
void outputLines(
const char * pszStr);
FLMBOOL needsPreprocessing( void);
RCODE preProcessParams( void);
@@ -7439,7 +7490,6 @@
char * pszBuffer);
RCODE displayShortHelpLines(
F_StringAcc * pStringAcc,
const char * pszShortHelp,
FLMUINT uiCharsPerLine);
@@ -7448,10 +7498,8 @@
FLMUINT uiVecLen);
RCODE parseOption(
const char * pszArg,
FLMBOOL * pbPrintedUsage);
const char * pszArg);
char * m_pszDescription;
char m_szExecBaseName[ F_PATH_MAX_SIZE];
F_Vector m_argVec;
FLMUINT m_uiArgVecIndex;
@@ -7464,8 +7512,7 @@
F_Arg * m_pRepeatingArg;
FLMUINT m_uiArgc;
F_Vector * m_pArgv;
F_ARG_OUTPUT_CALLBACK m_outputCallback;
void * m_pvOutputCallbackData;
IF_PrintfClient * m_pPrintfClient;
};
/****************************************************************************

File diff suppressed because it is too large Load Diff

1499
ftk/src/ftknet.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -145,6 +145,114 @@ private:
F_DynaBuf m_dynaBuf;
};
/****************************************************************************
Desc:
****************************************************************************/
class FLMEXP F_StdoutPrintfClient : public IF_PrintfClient
{
public:
F_StdoutPrintfClient()
{
}
virtual ~F_StdoutPrintfClient()
{
}
FINLINE FLMINT FLMAPI outputChar(
char cChar)
{
f_printf( "%c", cChar);
return( 1);
}
FINLINE FLMINT FLMAPI outputChar(
char cChar,
FLMUINT uiCount)
{
FLMINT iBytesOutput = (FLMINT)uiCount;
while( uiCount)
{
f_printf( "%c", cChar);
uiCount--;
}
return( iBytesOutput);
}
FINLINE FLMINT FLMAPI outputStr(
const char * pszStr,
FLMUINT uiLen)
{
f_printf( "%*s", (unsigned)uiLen, pszStr);
return( (FLMINT)uiLen);
}
FINLINE FLMINT FLMAPI colorFormatter(
char, // cFormatChar,
eColorType, // eColor,
FLMUINT) // uiFlags)
{
return( 0);
}
};
/****************************************************************************
Desc:
****************************************************************************/
class FLMEXP F_StderrPrintfClient : public IF_PrintfClient
{
public:
F_StderrPrintfClient()
{
}
virtual ~F_StderrPrintfClient()
{
}
FINLINE FLMINT FLMAPI outputChar(
char cChar)
{
f_printf( "%c", cChar);
return( 1);
}
FINLINE FLMINT FLMAPI outputChar(
char cChar,
FLMUINT uiCount)
{
FLMINT iBytesOutput = (FLMINT)uiCount;
while( uiCount)
{
f_printf( "%c", cChar);
uiCount--;
}
return( iBytesOutput);
}
FINLINE FLMINT FLMAPI outputStr(
const char * pszStr,
FLMUINT uiLen)
{
f_printf( "%*s", (unsigned)uiLen, pszStr);
return( (FLMINT)uiLen);
}
FINLINE FLMINT FLMAPI colorFormatter(
char, // cFormatChar,
eColorType, // eColor,
FLMUINT) // uiFlags)
{
return( 0);
}
};
/****************************************************************************
Desc: Parameter 'format' points to text following a '%' sign. Process
legal field information. Leave 'format' pointing at the format
@@ -885,3 +993,55 @@ FLMINT FLMAPI f_printf(
return( iLen);
}
/****************************************************************************
Desc:
****************************************************************************/
FLMINT FLMAPI f_errprintf(
const char * pszFormat,
...)
{
FLMINT iLen;
f_va_list args;
F_DynaPrintfClient printfClient;
f_va_start( args, pszFormat);
iLen = f_vprintf( &printfClient, pszFormat, &args);
f_va_end( args);
printfClient.outputChar( 0);
#ifndef FLM_RING_ZERO_NLM
fprintf( stderr, printfClient.getBufferPtr());
fflush( stderr);
#endif
return( iLen);
}
/*****************************************************************************
Desc:
******************************************************************************/
RCODE FLMAPI FlmAllocStdoutPrintfClient(
IF_PrintfClient ** ppClient)
{
if( (*ppClient = f_new F_StdoutPrintfClient) == NULL)
{
return( RC_SET( NE_FLM_MEM));
}
return( NE_FLM_OK);
}
/*****************************************************************************
Desc:
******************************************************************************/
RCODE FLMAPI FlmAllocStderrPrintfClient(
IF_PrintfClient ** ppClient)
{
if( (*ppClient = f_new F_StderrPrintfClient) == NULL)
{
return( RC_SET( NE_FLM_MEM));
}
return( NE_FLM_OK);
}

File diff suppressed because it is too large Load Diff