Changeset 15 in flair-src for trunk/lib/FlairCore/src/Socket.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Socket.cpp

    r2 r15  
    2323using std::string;
    2424
    25 namespace flair
    26 {
    27 namespace core
    28 {
     25namespace flair {
     26namespace core {
    2927
    30 Socket::Socket(const Object* parent, string name,uint16_t port): Object(parent,name) {
    31     pimpl_=new Socket_impl(this,name,port);
     28Socket::Socket(const Object *parent, string name, uint16_t port)
     29    : Object(parent, name) {
     30  pimpl_ = new Socket_impl(this, name, port);
    3231}
    3332
    34 Socket::Socket(const Object* parent, string name,string address,bool broadcast): Object(parent,name) {
    35     pimpl_=new Socket_impl(this,name,address,broadcast);
     33Socket::Socket(const Object *parent, string name, string address,
     34               bool broadcast)
     35    : Object(parent, name) {
     36  pimpl_ = new Socket_impl(this, name, address, broadcast);
    3637}
    3738
    38 Socket::~Socket() {
    39     delete pimpl_;
     39Socket::~Socket() { delete pimpl_; }
     40
     41void Socket::SendMessage(const char *message, size_t message_len) {
     42  pimpl_->SendMessage(message, message_len);
    4043}
    4144
    42 void Socket::SendMessage(const char* message,size_t message_len) {
    43     pimpl_->SendMessage(message,message_len);
     45void Socket::SendMessage(string message) { pimpl_->SendMessage(message); }
     46
     47ssize_t Socket::RecvMessage(char *buf, size_t buf_len, Time timeout, char *src,
     48                            size_t *src_len) {
     49  return pimpl_->RecvMessage(buf, buf_len, timeout, src, src_len);
    4450}
    4551
    46 void Socket::SendMessage(string message) {
    47     pimpl_->SendMessage(message);
     52void Socket::NetworkToHost(char *data, size_t dataSize) {
     53  if (core::IsBigEndian())
     54    return;
     55  if (dataSize == 1)
     56    return;
     57  if ((dataSize == 2) || (dataSize == 4) || (dataSize == 8) ||
     58      (dataSize == 16)) {
     59    char dataInHostEndianness[dataSize];
     60    for (unsigned int i = 0; i < dataSize; i++) {
     61      dataInHostEndianness[i] = data[dataSize - i - 1];
     62    }
     63    memcpy(data, dataInHostEndianness, dataSize);
     64    return;
     65  }
     66  throw std::runtime_error(
     67      string("Unsupported data size (") + std::to_string(dataSize) +
     68      string(") in host to network endianness conversion"));
    4869}
    4970
    50 ssize_t Socket::RecvMessage(char* buf,size_t buf_len,Time timeout,char* src,size_t* src_len) {
    51     return pimpl_->RecvMessage(buf,buf_len,timeout,src,src_len);
    52 }
    53 
    54 void Socket::NetworkToHost(char *data,size_t dataSize) {
    55     if (core::IsBigEndian()) return;
    56     if (dataSize==1) return;
    57     if ((dataSize==2)||(dataSize==4)||(dataSize==8)||(dataSize==16)) {
    58         char dataInHostEndianness[dataSize];
    59         for (unsigned int i=0;i<dataSize;i++) {
    60             dataInHostEndianness[i]=data[dataSize-i-1];
    61         }
    62         memcpy(data,dataInHostEndianness,dataSize);
    63         return;
     71void Socket::HostToNetwork(char *data, size_t dataSize) {
     72  if (IsBigEndian())
     73    return;
     74  if (dataSize == 1)
     75    return;
     76  if ((dataSize == 2) || (dataSize == 4) || (dataSize == 8) ||
     77      (dataSize == 16)) {
     78    char dataInNetworkEndianness[dataSize];
     79    for (unsigned int i = 0; i < dataSize; i++) {
     80      dataInNetworkEndianness[i] = data[dataSize - i - 1];
    6481    }
    65     throw std::runtime_error(string("Unsupported data size (")+std::to_string(dataSize)+string(") in host to network endianness conversion"));
    66 }
    67 
    68 void Socket::HostToNetwork(char *data,size_t dataSize) {
    69     if (IsBigEndian()) return;
    70     if (dataSize==1) return;
    71     if ((dataSize==2)||(dataSize==4)||(dataSize==8)||(dataSize==16)) {
    72         char dataInNetworkEndianness[dataSize];
    73         for (unsigned int i=0;i<dataSize;i++) {
    74             dataInNetworkEndianness[i]=data[dataSize-i-1];
    75         }
    76         memcpy(data,dataInNetworkEndianness,dataSize);
    77         return;
    78     }
    79     throw std::runtime_error(string("Unsupported data size (")+std::to_string(dataSize)+string(") in host to network endianness conversion"));
     82    memcpy(data, dataInNetworkEndianness, dataSize);
     83    return;
     84  }
     85  throw std::runtime_error(
     86      string("Unsupported data size (") + std::to_string(dataSize) +
     87      string(") in host to network endianness conversion"));
    8088}
    8189
Note: See TracChangeset for help on using the changeset viewer.