/************************************************************************** * * * Net TCP/IP connection class * * * * Programmed by Ondrej Jombik * * Copyright (c) 2000 Condy software inc. * * Copyright (c) 2001-2003 Platon Software Development Group * * All rights reserved. * * * * Updates: 1.4.2000, 5.10.2001 * * 20.9.2002 - Doxygen documentation * * * **************************************************************************/ /** * Net TCP/IP connection class * * @file platon/net/Connection.h * @author Ondrej Jombik * @version \$Platon: libplaton/platon/net/Connection.h,v 1.15 2003/04/23 19:28:36 nepto Exp $ * @date 2000-2003 */ /* * Bez objektov uz ani krok. Ale nie vazne, toto vzniklo kvoli tomu, * ze sa v buducnosti rata s niecim takym ako * netConnection atl_cnx[200]; for(k=...)atl_cnx[k].SetHost(...); * Niezeby som chcel mat nejakom talkeri 200 dvojitych identit, * ale nikdy nevies kedy sa Ti nieco taketo zide...:))) * * Nepto [1/4/2000] */ #ifndef _PLATON_NET_Connection_H #define _PLATON_NET_Connection_H /** Maximum hostname size */ #ifndef NET_CONNECTION_MAX_HOST_SIZE # define NET_CONNECTION_MAX_HOST_SIZE 100 #endif /** End of line string; used by netConnection::ReadLine() method. */ #ifndef NET_CONNECTION_EOL # define NET_CONNECTION_EOL "\r\n" #endif /** Default port (telnet) */ #ifndef NET_CONNECTION_PORT # define NET_CONNECTION_PORT 23 #endif #ifdef __cplusplus /** * Net connection class * * @class netConnection * @author Ondrej Jombik * @version \$Platon: libplaton/platon/net/Connection.h,v 1.15 2003/04/23 19:28:36 nepto Exp $ * @date 2000-2003 */ class netConnection { private: int handle; int port; char host[NET_CONNECTION_MAX_HOST_SIZE+1]; char*__rbuf; public: /** * Object constructor * * @param host hostname * @param port port */ netConnection(const char*host=NULL,const int port=NET_CONNECTION_PORT); /** * Object destructor */ ~netConnection(void); /** * @name Property setting methods */ /**@{*/ /** * Sets new port * * @param newport new port number * @note inline method */ inline void setPort(const int newport); /** * Sets new host * * @param newhost new hostname * @param newport new port number */ void setHost(const char*newhost,const int newport=0); /**@}*/ /** * @name Connection manipulation methods */ /**@{*/ /** * Connects to remote host * * @return non-zero value if connection is estabilished, 0 otherwise */ int connect(void); /** * Disconnects from remote host */ void disconnect(void); /** * Returns if connection is opened * * @return non-zero value if connection is estabilished, 0 otherwise * @note inline method */ int isConnected(void); /**@}*/ /** * @name Writting methods */ /**@{*/ /** * Writes newline character to connection * * @return number of byttes written, -1 on error, * see write() syscall for more info */ int writeLine(void); /** * Writes string and appends newline to connection * * @param s string to write * @return number of byttes written, -1 on error, * see write() syscall for more info */ int writeLine(const char*s); /** * Writes string to connection * * @param s string to write * @return number of byttes written, -1 on error, * see write() syscall for more info */ int writeStr(const char*s); /** * Writes data to connection * * @param s data to write * @param len length of data * @return number of byttes written, -1 on error, * see write() syscall for more info */ int writeData(const void*p,int len); /**@}*/ /** * @name Reading methods */ /**@{*/ /** * Read data from connection * * @retval buffer pointer where to store read data * @param size buffer size * @return count of read bytes * * Returned value of 0 may but must not indicate connection lost. If you * want to check your connection state, use isConnected() method for this * purpose. */ int readData(char*buffer,const int size); /** * Read one line from connection * * @retval buffer pointer where to store read line * @param size buffer size * @return count of read bytes, iow. line size * @see readData for more info about returned value of 0 handling */ int readLine(char*buffer,const int size); /**@}*/ }; #endif /* #ifdef _cplusplus */ #endif /* #ifndef _PLATON_NET_Connection_H */