]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/connection.cpp
Mas msg lindos
[z.facultad/75.42/plaqui.git] / Server / src / connection.cpp
index 1dc6b6d3d9a45d01385021035114312d84aa0194..cf0e293cdb4a92cd79a310b31e6be230db23e029 100644 (file)
@@ -39,42 +39,60 @@ namespace Server {
 
 Connection::~Connection(void) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": destructor." << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": destructor." << endl;
 #endif // DEBUG
 }
 
 Connection::Connection(const sockbuf::sockdesc& sd):
                socket(sd) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": sd = " << sd.sock << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": sd = " << sd.sock;
+#endif // DEBUG
+       host = socket->peerhost();
+       port = socket->peerport();
+#ifdef DEBUG
+       cerr << " | host = " << host << " | port = " << port << endl;
+#endif // DEBUG
+}
+
+Connection::Connection(const sockbuf::type& type, const std::string& host,
+               const Port& port): socket(type), host(host), port(port) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": type = " << type << " | host = " << host
+               << " | port = " << port << endl;
 #endif // DEBUG
 }
 
-Connection::Connection(sockbuf::type type):
-               socket(type) {
+Connection::Connection(const std::string& host, const Port& port):
+               host(host), port(port) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": type = " << type << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": host = " << host << " | port = " << port << endl;
 #endif // DEBUG
 }
 
-void Connection::finish(bool attach) {
-       //socket_mutex.lock();
-       socket->shutdown(sockbuf::shut_readwrite);
-       //socket_mutex.unlock();
-       Runnable::finish(attach);
+void Connection::finish(void) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": finish();" << endl;
+#endif // DEBUG
+       Runnable::finish();
+       try {
+               // Para que el socket retorne el control, cierro sus canales de E/S.
+               socket->shutdown(sockbuf::shut_readwrite);
+       } catch (const sockerr& e) {
+               signal_error().emit(e.serrno(), e.errstr());
+       }
 }
 
-string Connection::get_peerhost(void) {
-       //socket_mutex.lock();
-       string host = socket->peerhost();
-       //socket_mutex.unlock();
+const string& Connection::get_host(void) const {
        return host;
 }
 
-unsigned Connection::get_peerport(void) {
-       //socket_mutex.lock();
-       unsigned port = socket->peerport();
-       //socket_mutex.unlock();
+const Connection::Port& Connection::get_port(void) const {
        return port;
 }