: bharatvaj/forwarder

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 #ifndef _IP_DEVICE_H
#define _IP_DEVICE_H

#include <sys/socket.h>
#include <unistd.h>

#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>

#include <comm.h>

#include <device/Device.hpp>

namespace wa {
class IPDevice : Device {
private:
  xs_SOCKET fd;
  bool isTcp;

public:
  IPDevice(xs_SOCKET fd) : fd(fd), isTcp(true) {}

  int read(char *str, int bytesToRead) override {
    return ::read(fd, str, bytesToRead);
  }

  int write(char *str, int bytesToSend) override {
    return ::write(fd, str, bytesToSend);
  }

  void disconnect(){
    ::close(fd);
  }

  ~IPDevice() { comm_close_socket(fd); }
};
} // namespace wa
#endif