Commit bf7aa142 authored by Seblu's avatar Seblu
Browse files

Les connexions ont maintenant in id unique

parent e6ac348e
Loading
Loading
Loading
Loading

sls/trunk/BUGS

0 → 100644
+0 −0

Empty file added.

+0 −4
Original line number Diff line number Diff line
Gerer les control-C sur les sockets. Le server ne ferme pas la connection...
Implementer un conn id pour qu'un serveur puisse numeroter les connecxions

+8 −3
Original line number Diff line number Diff line
@@ -35,7 +35,13 @@ Client *Client::login(Connection &c) {
    return login_fail(c);

  if (sscanf(slogin.c_str(), "HOST %512s\n", loginbuf) == 1) {
    std::cout << "Host " << loginbuf << " logged from " << c.getremoteip()
    // check login and password

    // Register login and pass in client

    // Print succefful login
    std::cout << "Connection id " << c.getid() << ": Host " << loginbuf 
	      << " logged from " << c.getremoteip()
	      << " on port " << c.getremoteport() << ".\n";
    return new Daemon(c);
  }
@@ -47,8 +53,7 @@ Client *Client::login(Connection &c) {
}

Client *Client::login_fail(Connection &c) {
  std::cout << "Bad authentification from " << c.getremoteip() << " on port "
	    << c.getremoteport() << ".\n";
  std::cout << "Connection id " << c.getid() << ": Bad authentification.\n";
  c.sendln("Bad authentification.");
  return 0;
}
+4 −1
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
Daemon::Daemon(Connection &c) : Client(c) {}

void Daemon::exec() {
  // send scripts

  // starting scripts

  c_.sendln("EXIT");
  while (1) { c_.sendln("toto"); }
}
+16 −2
Original line number Diff line number Diff line
@@ -27,6 +27,14 @@
#include <errno.h>
#include <poll.h>

/*******************************************************************************
 ** Class method
 ******************************************************************************/
unsigned long int Connection::getconnid() {
  static unsigned long int id = 1;
  return id++;
}

/*******************************************************************************
 ** Public method
 ******************************************************************************/
@@ -36,14 +44,16 @@
 *
 * @param fd socket of the connection (-1) is not exist
 */
Connection::Connection(int fd) : socket_fd_(fd), local_port_(-1), remote_port_(-1) {
Connection::Connection(int fd) : socket_fd_(fd), local_port_(-1), remote_port_(-1), id_(0) {
  pthread_mutex_init(&c_mutex_, 0);
  pthread_mutex_init(&r_mutex_, 0);
  pthread_mutex_init(&w_mutex_, 0);

  if (socket_fd_ >= 0)
  if (socket_fd_ >= 0) {
    id_ = getconnid();
    setallinfo_();
  }
}

/**
 * Destructor
@@ -352,6 +362,10 @@ int Connection::getremoteport() {
  return port;
}

unsigned long int Connection::getid() {
  return id_;
}

int Connection::getsocket() {
  pthread_mutex_lock(&c_mutex_);
  int ret = socket_fd_;
Loading