83 lines
1.8 KiB
C++
83 lines
1.8 KiB
C++
|
|
#include "xsock.h"
|
|
|
|
// constantes utilisées dans XSock.cpp et dans XSockUDP.cpp
|
|
#define NBPORTSPUB 64512
|
|
#define PNUMPORTPUB 1025
|
|
#define GETPORTPUB() PNUMPORTPUB+(rand()%NBPORTSPUB)
|
|
|
|
#define VERBGAPP 0
|
|
#define VERBACCEPT 0
|
|
#define VERBLAUNCHCLI 0
|
|
#define VERBSEND 0
|
|
#define VERBRECV 0
|
|
|
|
|
|
#define VERBOSE 1
|
|
#define ACK 0
|
|
#define NON_ACK 1
|
|
#define HI 2
|
|
#define BYE 3
|
|
#define SIZEADD 2*sizeof(u_short) + 2*sizeof(u_int)
|
|
#define SIZESTART 2*sizeof(u_short) + sizeof(u_int)
|
|
#define NBMAXTENTATIVES 16
|
|
#define TIMERBASE 10000
|
|
|
|
using namespace std;
|
|
using namespace XSockExcept;
|
|
|
|
|
|
namespace XSock {
|
|
/*
|
|
extern u_int nbConn;
|
|
|
|
void XSock::AddConnectionToManage(int desc){
|
|
|
|
}*/
|
|
|
|
void XSock::close_udp(){
|
|
::close(this->_sockFd);
|
|
}
|
|
|
|
void XSock::launch_udp_client(){
|
|
if(VERBLAUNCHCLI >=1){cout << "--> launch_udp_client\n\tentree dans launch_udp_client" << endl;}
|
|
if(this->_server.sin_port == htons(0)){
|
|
throw eXSockNotReady();
|
|
}else{
|
|
// rien a faire... je crois
|
|
}
|
|
}
|
|
|
|
void XSock::launch_udp_server(){
|
|
/* TODO: choisir mono ou multi-processus */
|
|
/* meme remarque que dans TCP */
|
|
if((this->_sockFd=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP))==-1){
|
|
perror("eInvalidSocket");
|
|
throw eInvalidSocket();
|
|
}
|
|
|
|
if (bind(this->_sockFd,
|
|
(struct sockaddr*)&this->_server,
|
|
sizeof(this->_server))==-1)
|
|
{
|
|
perror("eUnableToBind");
|
|
throw eUnableToBind();
|
|
}
|
|
}
|
|
|
|
XSock XSock::accept_udp(){
|
|
// rien a faire
|
|
}
|
|
|
|
ssize_t XSock::recv_udp(void *bufferData, ssize_t size){
|
|
ssize_t p = read(this->_sockFd, bufferData, size);
|
|
// traiter les erreurs...
|
|
return p;
|
|
}
|
|
|
|
ssize_t XSock::send_udp(const void *bufferData, ssize_t size){
|
|
ssize_t p = write(this->_sockFd, bufferData, size);
|
|
// traiter les erreurs...
|
|
return p;
|
|
}
|
|
}
|