Kyoto Tycoon

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Friends
kyototycoon::Socket Class Reference

Network stream abstraction based on TCP/IP. More...

`#include <ktsocket.h>`

List of all members.

## Public Member Functions

| Socket ()
| Default constructor.
| ~Socket ()
| Destructor.
const char * | error ()
| Get the last happened error information.
bool | open (const std::string &expr)
| Open a client socket.
bool | close (bool grace=true)
| Close the socket.
bool | send (const void *buf, size_t size)
| Send data.
bool | send (const std::string &str)
| Send data.
bool | printf (const char *format,...)
| Send formatted data.
bool | vprintf (const char *format, va_list ap)
| Send formatted data.
bool | receive (void *buf, size_t size)
| Receive data.
int32_t | receive_byte ()
| Receive one byte.
bool | undo_receive_byte (int32_t c)
| Push one byte back.
bool | receive_line (void *buf, size_t max)
| Receive one line of characters.
size_t | left_size ()
| Get the size of left data in the receiving buffer.
bool | abort ()
| Abort the current operation.
bool | set_timeout (double timeout)
| Set the timeout of each operation.
const std::string | expression ()
| Get the expression of the socket.
int32_t | descriptor ()
| Get the descriptor integer.
void | set_event_flags (uint32_t flags)
| Set event flags.
uint32_t | event_flags ()
| Get the current event flags.

## Static Public Member Functions

static std::string | get_local_host_name ()
| Get the primary name of the local host.
static std::string | get_host_address (const std::string &name)
| Get the address of a host.

## Friends

class | ServerSocket

## Detailed Description

Network stream abstraction based on TCP/IP.

## Constructor & Destructor Documentation

kyototycoon::Socket::Socket | ( |  | ) | `[explicit]`

Default constructor.

kyototycoon::Socket::~Socket | ( |  | ) |

Destructor.

## Member Function Documentation

const char* kyototycoon::Socket::error | ( |  | ) |

Get the last happened error information.

Returns:
  the last happened error information.

bool kyototycoon::Socket::open | ( | const std::string & | expr | ) |

Open a client socket.

Parameters:

  expr | an expression of the address and the port of the server.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::close | ( | bool | grace = `true` | ) |

Close the socket.

Parameters:

  grace | true for graceful shutdown, or false for immediate disconnection.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::send | ( | const void * | buf,
|  | size_t | size
| ) |  |

Send data.

Parameters:

  buf | the pointer to a data region to send.
  size | the size of the data region.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::send | ( | const std::string & | str | ) |

Send data.

Parameters:

  str | a string to send.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::printf | ( | const char * | format,
|  |  | ...
| ) |  |

Send formatted data.

Parameters:

  format | the printf-like format string. The conversion character `' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', and `'.
  ... | used according to the format string.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::vprintf | ( | const char * | format,
|  | va_list | ap
| ) |  |

Send formatted data.

Parameters:

  format | the printf-like format string. The conversion character `' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', and `'.
  ap | used according to the format string.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::receive | ( | void * | buf,
|  | size_t | size
| ) |  |

Receive data.

Parameters:

  buf | the pointer to the buffer into which the received data is written.
  size | the size of the data to receive.

Returns:
  true on success, or false on failure.

int32_t kyototycoon::Socket::receive_byte | ( |  | ) |

Receive one byte.

Returns:
  the received byte or -1 on failure.

bool kyototycoon::Socket::undo_receive_byte | ( | int32_t | c | ) |

Push one byte back.

Parameters:

  c | specifies the byte.

Returns:
  true on success, or false on failure.

Note:
  The character is available for subsequent receive operations. Only one pushback is guaranteed.

bool kyototycoon::Socket::receive_line | ( | void * | buf,
|  | size_t | max
| ) |  |

Receive one line of characters.

Parameters:

  buf | the pointer to the buffer into which the received data is written.
  max | the maximum size of the data to receive. It must be more than 0.

Returns:
  true on success, or false on failure.

size_t kyototycoon::Socket::left_size | ( |  | ) |

Get the size of left data in the receiving buffer.

Returns:
  the size of left data in the receiving buffer.

bool kyototycoon::Socket::abort | ( |  | ) |

Abort the current operation.

Returns:
  true on success, or false on failure.

bool kyototycoon::Socket::set_timeout | ( | double | timeout | ) |

Set the timeout of each operation.

Parameters:

  timeout | the timeout of each operation in seconds.

Returns:
  true on success, or false on failure.

const std::string kyototycoon::Socket::expression | ( |  | ) |

Get the expression of the socket.

Returns:
  the expression of the socket or an empty string on failure.

int32_t kyototycoon::Socket::descriptor | ( |  | ) | `[virtual]`

Get the descriptor integer.

Returns:
  the descriptor integer, or -1 on failure.

Implements kyototycoon::Pollable.

void kyototycoon::Socket::set_event_flags | ( | uint32_t | flags | ) | `[virtual]`

Set event flags.

Parameters:

  flags | specifies the event mode. The following may be added by bitwise-or: Socket::EVINPUT for input events, Socket::EVOUTPUT for output events, Socket::EVEXCEPT for exception events.

Implements kyototycoon::Pollable.

uint32_t kyototycoon::Socket::event_flags | ( |  | ) | `[virtual]`

Get the current event flags.

Returns:
  the current event flags.

Implements kyototycoon::Pollable.

static std::string kyototycoon::Socket::get_local_host_name | ( |  | ) | `[static]`

Get the primary name of the local host.

Returns:
  the host name, or an empty string on failure.

static std::string kyototycoon::Socket::get_host_address | ( | const std::string & | name | ) | `[static]`

Get the address of a host.

Returns:
  the host address, or an empty string on failure.