Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Socket Class Reference

A communication socket device. More...

#include <msocket.h>

Inheritance diagram for Socket:

IODevice List of all members.

Public Methods

virtual bool open (int mode)
virtual uint size () const
virtual int at () const
bool reset ()
virtual int readBlock (char *data, uint maxlen)
virtual int writeBlock (const char *data, uint len)
virtual int readLine (char *data, uint maxlen)
int writeBlock (const String &)
virtual char getch ()
virtual void putch (char ch)
virtual void ungetch (char ch)

Detailed Description

A communication socket device.

Definition at line 33 of file msocket.h.


Member Function Documentation

virtual int at   const [inline, virtual]
 

Returns the current position in device.

Only meaningful for "block devices", which have a defined size.

Reimplemented from IODevice.

Definition at line 49 of file msocket.h.

virtual char getch   [virtual]
 

Reads and returns one character from device.

Returns:
The character read.

Reimplemented from IODevice.

bool open int    mode [virtual]
 

This file is part of the MagiC++ library.

* * Copyright (C) 1998-2002 Marko Grönroos <magi@iki.fi> * *

* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; see the file COPYING.LIB. If * not, write to the Free Software Foundation, Inc., 59 Temple Place *

  • Suite 330, Boston, MA 02111-1307, USA. * *

Reimplemented from IODevice.

Definition at line 27 of file msocket.cc.

virtual void putch char    ch [virtual]
 

Writes one character to device.

Reimplemented from IODevice.

virtual int readBlock char *    data,
uint    maxlen
[virtual]
 

Reads a data block from the device.

Returns:
Returns the number of bytes actually read, or 0 if none.

Reimplemented from IODevice.

virtual int readLine char *    data,
uint    maxlen
[virtual]
 

Reads a newline (\n) terminated line from device.

The buffer must be allocated to contain the given length of bytes.

The function spares one byte for the terminating zero, so the actual maximum number of bytes read is one less than the maxlen parameter.

Example:

  // Read in chunks
  char buffer [1024];
  int bytesRead = 0;
  int totalRead = 0;
  while (bytesRead = mpDevice->readLine (buffer, 1024)) {
      linebuf.append (buffer);
      totalRead += bytesRead;
  }

Note:
The default implementation reads the line with getch(). If you are implementing a device, you may want to implement a faster version that uses lower-level functions.
Returns:
Returns the number of bytes actually read, or 0 if none.

Reimplemented from IODevice.

bool reset  
 

Resets the state of the device to a newly opened state.

Returns:
TRUE if successful, FALSE if an error occurred.

Reimplemented from IODevice.

virtual uint size   const [inline, virtual]
 

Returns the size of the file in bytes.

Only meaningful for "block devices", which have a defined size.

Reimplemented from IODevice.

Definition at line 48 of file msocket.h.

virtual void ungetch char    ch [virtual]
 

Unreads one character from device.

The function has no meaning if the device is already at beginning.

Reimplemented from IODevice.

int writeBlock const String  
 

Writes a data block to device.

Returns:
Returns the number of bytes actually written, or 0 if none.

Reimplemented from IODevice.

virtual int writeBlock const char *    data,
uint    len
[virtual]
 

Writes a data block to device.

Returns:
Returns the number of bytes actually written, or 0 if none.

Reimplemented from IODevice.


The documentation for this class was generated from the following files:
Generated on Thu Feb 10 20:06:43 2005 for LibMagiC by doxygen1.2.18