Commit 193ed270 authored by Seblu's avatar Seblu

Ajout de connection dans sll

parent 023042a3
This diff is collapsed.
/*
This file is part of SLS.
Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
SLS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
SLS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SLS; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CONNECTION_HH
# define CONNECTION_HH
# include <pthread.h>
class Connection {
// class methods
public:
unsigned long int getconnid();
// public methods
public:
Connection(int fd = -1);
virtual ~Connection();
void connect(const char *addr, int port);
void listen(int port, int max);
void disconnect();
bool connected();
Connection *accept();
// send methods
inline void send(const string &data);
void send(const char* buf, size_t len);
inline void sendln(const string &data);
void sendln(const char* buf, size_t len);
// recv methods
string recvln();
// info methods
string getlocalip();
int getlocalport();
string getremoteip();
int getremoteport();
unsigned long int getid();
int getsocket();
// protected methods
protected:
void socket_();
void disconnect_();
inline void setallinfo_();
void setlocalip_();
void setlocalport_();
void setremoteip_();
void setremoteport_();
// Protected datas
protected:
int socket_fd_; // connection socket
// storage of info about connection
int local_port_;
int remote_port_;
string local_ip_;
string remote_ip_;
unsigned long int id_;
string rbuf_; // read buffer
string wbuf_; // write buffer
pthread_mutex_t c_mutex_; // connection mutex
pthread_mutex_t r_mutex_; // read mutex
pthread_mutex_t w_mutex_; // write mutex
};
# include "connection.hxx"
#endif
/*
This file is part of SLS.
Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
SLS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
SLS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SLS; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*******************************************************************************
** Public method
******************************************************************************/
/**
* Send @param data on socket
*/
void Connection::send(const string &data) {
send(data.c_str(), data.length());
}
/**
* Send @param data followed by '\n' on socket
*/
void Connection::sendln(const string &data) {
sendln(data.c_str(), data.length());
}
/*******************************************************************************
** Protected method
******************************************************************************/
/**
* Set all information about a connection
*/
void Connection::setallinfo_() {
setlocalip_();
setlocalport_();
setremoteip_();
setremoteport_();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment