[svn] commit: r1215 - /trunk/src/lib/cc/session.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 8 20:15:05 UTC 2010
Author: jinmei
Date: Mon Mar 8 20:15:05 2010
New Revision: 1215
Log:
fixed regression in the previous exception-safe fix
Modified:
trunk/src/lib/cc/session.cc
Modified: trunk/src/lib/cc/session.cc
==============================================================================
--- trunk/src/lib/cc/session.cc (original)
+++ trunk/src/lib/cc/session.cc Mon Mar 8 20:15:05 2010
@@ -64,8 +64,19 @@
// with the RAII approach.
class SocketHolder {
public:
- SocketHolder(int fd) : fd_(fd) {}
- ~SocketHolder() { close (fd_); }
+ SocketHolder(SessionImpl* obj, int fd) : impl_obj_(obj), fd_(fd)
+ {
+ impl_obj_->sock_ = fd;
+ }
+ ~SocketHolder()
+ {
+ if (fd_ >= 0) {
+ close(fd_);
+ impl_obj_->sock_ = -1;
+ }
+ }
+ void clear() { fd_ = -1; }
+ SessionImpl* impl_obj_;
int fd_;
};
}
@@ -80,7 +91,7 @@
throw SessionError("socket() failed");
}
- SocketHolder socket_holder(s);
+ SocketHolder socket_holder(impl_, s);
sin.sin_family = AF_INET;
sin.sin_port = htons(9912);
@@ -91,8 +102,9 @@
#endif
ret = connect(s, (struct sockaddr *)&sin, sizeof(sin));
- if (ret < 0)
+ if (ret < 0) {
throw SessionError("Unable to connect to message queue");
+ }
//
// send a request for our local name, and wait for a response
@@ -109,7 +121,7 @@
impl_->lname_ = msg->get("lname")->stringValue();
cout << "My local name is: " << impl_->lname_ << endl;
- impl_->sock_ = socket_holder.fd_;
+ socket_holder.clear();
}
//
@@ -124,6 +136,8 @@
unsigned short header_length_net = htons(header_length);
unsigned int ret;
+ assert(impl_->sock_ != -1);
+
ret = write(impl_->sock_, &length_net, 4);
if (ret != 4)
throw SessionError("Short write");
More information about the bind10-changes
mailing list