drivers/can_tcp_win32/Socket.cpp
author etisserant
Wed, 16 Jul 2008 15:21:04 +0200
changeset 495 b2d6307a89fa
parent 355 12adbd08e10c
permissions -rwxr-xr-x
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
355
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     1
/* 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     2
   Socket.cpp
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     3
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     4
   Copyright (C) 2002-2004 René Nyffenegger
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     5
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     6
   This source code is provided 'as-is', without any express or implied
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     7
   warranty. In no event will the author be held liable for any damages
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     8
   arising from the use of this software.
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
     9
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    10
   Permission is granted to anyone to use this software for any purpose,
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    11
   including commercial applications, and to alter it and redistribute it
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    12
   freely, subject to the following restrictions:
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    13
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    14
   1. The origin of this source code must not be misrepresented; you must not
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    15
      claim that you wrote the original source code. If you use this source code
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    16
      in a product, an acknowledgment in the product documentation would be
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    17
      appreciated but is not required.
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    18
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    19
   2. Altered source versions must be plainly marked as such, and must not be
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    20
      misrepresented as being the original source code.
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    21
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    22
   3. This notice may not be removed or altered from any source distribution.
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    23
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    24
   René Nyffenegger rene.nyffenegger@adp-gmbh.ch
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    25
*/
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    26
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    27
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    28
#include "Socket.h"
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    29
#include <iostream>
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    30
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    31
using namespace std;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    32
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    33
int Socket::nofSockets_= 0;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    34
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    35
void Socket::Start() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    36
  if (!nofSockets_) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    37
    WSADATA info;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    38
    if (WSAStartup(MAKEWORD(2,0), &info)) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    39
      throw "Could not start WSA";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    40
    }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    41
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    42
  ++nofSockets_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    43
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    44
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    45
void Socket::End() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    46
  WSACleanup();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    47
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    48
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    49
Socket::Socket() : s_(0) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    50
  Start();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    51
  // UDP: use SOCK_DGRAM instead of SOCK_STREAM
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    52
  s_ = socket(AF_INET,SOCK_STREAM,0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    53
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    54
  if (s_ == INVALID_SOCKET) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    55
    throw "INVALID_SOCKET";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    56
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    57
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    58
  refCounter_ = new int(1);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    59
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    60
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    61
Socket::Socket(SOCKET s) : s_(s) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    62
  Start();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    63
  refCounter_ = new int(1);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    64
};
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    65
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    66
Socket::~Socket() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    67
  if (! --(*refCounter_)) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    68
    Close();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    69
    delete refCounter_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    70
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    71
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    72
  --nofSockets_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    73
  if (!nofSockets_) End();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    74
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    75
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    76
Socket::Socket(const Socket& o) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    77
  refCounter_=o.refCounter_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    78
  (*refCounter_)++;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    79
  s_         =o.s_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    80
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    81
  nofSockets_++;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    82
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    83
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    84
Socket& Socket::operator=(Socket& o) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    85
  (*o.refCounter_)++;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    86
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    87
  refCounter_=o.refCounter_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    88
  s_         =o.s_;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    89
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    90
  nofSockets_++;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    91
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    92
  return *this;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    93
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    94
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    95
void Socket::Close() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    96
  closesocket(s_);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    97
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    98
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
    99
std::string Socket::ReceiveBytes() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   100
  std::string ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   101
  char buf[1024];
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   102
 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   103
  while (1) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   104
    u_long arg = 0;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   105
    if (ioctlsocket(s_, FIONREAD, &arg) != 0)
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   106
      break;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   107
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   108
    if (arg == 0)
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   109
      break;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   110
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   111
    if (arg > 1024) arg = 1024;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   112
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   113
    int rv = recv (s_, buf, arg, 0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   114
    if (rv <= 0) break;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   115
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   116
    std::string t;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   117
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   118
    t.assign (buf, rv);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   119
    ret += t;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   120
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   121
 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   122
  return ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   123
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   124
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   125
std::string Socket::ReceiveLine() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   126
  std::string ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   127
  while (1) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   128
    char r;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   129
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   130
    switch(recv(s_, &r, 1, 0)) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   131
      case 0: // not connected anymore;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   132
              // ... but last line sent
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   133
              // might not end in \n,
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   134
              // so return ret anyway.
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   135
        return ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   136
      case -1:
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   137
        return "";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   138
//      if (errno == EAGAIN) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   139
//        return ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   140
//      } else {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   141
//      // not connected anymore
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   142
//      return "";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   143
//      }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   144
    }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   145
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   146
    if (r == '\n')  return ret;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   147
    ret += r;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   148
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   149
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   150
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   151
void Socket::SendLine(std::string s) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   152
  s += '\n';
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   153
  send(s_,s.c_str(),s.length(),0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   154
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   155
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   156
void Socket::SendBytes(const std::string& s) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   157
  send(s_,s.c_str(),s.length(),0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   158
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   159
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   160
SocketServer::SocketServer(int port, int connections, TypeSocket type) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   161
  sockaddr_in sa;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   162
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   163
  memset(&sa, 0, sizeof(sa));
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   164
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   165
  sa.sin_family = PF_INET;             
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   166
  sa.sin_port = htons(port);          
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   167
  s_ = socket(AF_INET, SOCK_STREAM, 0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   168
  if (s_ == INVALID_SOCKET) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   169
    throw "INVALID_SOCKET";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   170
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   171
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   172
  if(type==NonBlockingSocket) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   173
    u_long arg = 1;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   174
    ioctlsocket(s_, FIONBIO, &arg);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   175
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   176
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   177
  /* bind the socket to the internet address */
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   178
  if (bind(s_, (sockaddr *)&sa, sizeof(sockaddr_in)) == SOCKET_ERROR) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   179
    closesocket(s_);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   180
    throw "INVALID_SOCKET";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   181
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   182
  
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   183
  listen(s_, connections);                               
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   184
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   185
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   186
Socket* SocketServer::Accept() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   187
  SOCKET new_sock = accept(s_, 0, 0);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   188
  if (new_sock == INVALID_SOCKET) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   189
    int rc = WSAGetLastError();
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   190
    if(rc==WSAEWOULDBLOCK) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   191
      return 0; // non-blocking call, no request pending
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   192
    }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   193
    else {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   194
      throw "Invalid Socket";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   195
    }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   196
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   197
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   198
  Socket* r = new Socket(new_sock);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   199
  return r;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   200
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   201
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   202
SocketClient::SocketClient(const std::string& host, int port) : Socket() {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   203
  std::string error;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   204
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   205
  hostent *he;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   206
  if ((he = gethostbyname(host.c_str())) == 0) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   207
    error = strerror(errno);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   208
    throw error;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   209
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   210
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   211
  sockaddr_in addr;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   212
  addr.sin_family = AF_INET;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   213
  addr.sin_port = htons(port);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   214
  addr.sin_addr = *((in_addr *)he->h_addr);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   215
  memset(&(addr.sin_zero), 0, 8); 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   216
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   217
  if (::connect(s_, (sockaddr *) &addr, sizeof(sockaddr))) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   218
    error = strerror(WSAGetLastError());
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   219
    throw error;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   220
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   221
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   222
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   223
SocketSelect::SocketSelect(Socket const * const s1, Socket const * const s2, TypeSocket type) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   224
  FD_ZERO(&fds_);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   225
  FD_SET(const_cast<Socket*>(s1)->s_,&fds_);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   226
  if(s2) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   227
    FD_SET(const_cast<Socket*>(s2)->s_,&fds_);
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   228
  }     
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   229
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   230
  TIMEVAL tval;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   231
  tval.tv_sec  = 0;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   232
  tval.tv_usec = 1;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   233
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   234
  TIMEVAL *ptval;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   235
  if(type==NonBlockingSocket) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   236
    ptval = &tval;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   237
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   238
  else { 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   239
    ptval = 0;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   240
  }
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   241
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   242
  if (select (0, &fds_, (fd_set*) 0, (fd_set*) 0, ptval) == SOCKET_ERROR) 
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   243
    throw "Error in select";
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   244
}
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   245
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   246
bool SocketSelect::Readable(Socket const* const s) {
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   247
  if (FD_ISSET(s->s_,&fds_)) return true;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   248
  return false;
12adbd08e10c TCP broadcasting chat server to exchange CAN messages between CanFestival nodes on windows. This let user simulate a CANopen network on windows.
etisserant
parents:
diff changeset
   249
}