29.07.2011 - fundamental new
This commit is contained in:
24
piethernet.h
24
piethernet.h
@@ -4,22 +4,22 @@
|
||||
#include "pithread.h"
|
||||
#include "pistring.h"
|
||||
#ifndef WINDOWS
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
#else
|
||||
# include <winsock2.h>
|
||||
# define SHUT_RDWR SD_BOTH
|
||||
# include <winsock2.h>
|
||||
# define SHUT_RDWR SD_BOTH
|
||||
#endif
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
typedef bool (*EthernetFunc)(void * , char * );
|
||||
typedef bool (*EthernetFunc)(void * , char * , int );
|
||||
|
||||
class PIEthernet: public PIThread
|
||||
{
|
||||
public:
|
||||
// slot is any function format "bool <func>(void*, char*)"
|
||||
// slot is any function format "bool <func>(void*, char*, int)"
|
||||
PIEthernet(PIString ip = "", int port = 0, void * data = 0, EthernetFunc slot = 0);
|
||||
~PIEthernet();
|
||||
|
||||
@@ -32,22 +32,22 @@ public:
|
||||
bool send(char * data, int size);
|
||||
bool init();
|
||||
bool initSend();
|
||||
bool initialized() const {return sock != -1;}
|
||||
bool receiverInitialized() const {return sock != -1;}
|
||||
bool senderInitialized() const {return sock_s != -1;}
|
||||
void terminate();
|
||||
inline const char * buffer() const {return buffer_;}
|
||||
|
||||
private:
|
||||
void begin();
|
||||
void run();
|
||||
void end();
|
||||
|
||||
|
||||
int sock, sock_s, port_, port_s, wrote;
|
||||
int sock, sock_s, port_, port_s, wrote, readed, tries;
|
||||
sockaddr_in addr_, saddr_;
|
||||
PIString ip_, ip_s;
|
||||
EthernetFunc ret_func;
|
||||
char * buffer;
|
||||
void * data;
|
||||
int readed;
|
||||
char buffer_[BUFFER_SIZE];
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user