[Log4cplus-devel] [log4cplus:bugs] #318 socket copy operator closes the socket
Logging Framework for C++
Brought to you by:
wilx
From: Václav H. <wi...@us...> - 2017-01-30 20:21:15
|
The problem here is that historically, `Socket s(rhs)` would move data from `rhs` to `s`. This is not good but I am not inclined to change this. This is fixed on master branch by proper implementation of move constructor and move assignment operator. Thereofre I am closing this as wront-fix for 1.2.x branch. --- ** [bugs:#318] socket copy operator closes the socket** **Status:** open **Group:** v1.2.x **Labels:** socket **Created:** Sun May 31, 2015 08:14 AM UTC by Alexis Wilke **Last Updated:** Sun May 31, 2015 09:02 AM UTC **Owner:** Václav Haisman **Attachments:** - [0002-log4cplus-1.2.0-rc3-socket-copy-operator.patch](https://sourceforge.net/p/log4cplus/bugs/318/attachment/0002-log4cplus-1.2.0-rc3-socket-copy-operator.patch) (262 Bytes; text/x-patch) As I'm working on the simpleserver to make it work properly (especially, so it does not leak all the ClientThread objects--this will be another issue), I noticed that the copy constructor properly transferred a socket, whereas, the copy assignment closes the socket! So if I do this it works as expected: Socket s(rhs); // rhs transferred to s (now rhs is considered closed) Whereas, doing this closes the socket: Socket s; s = rhs; // s is a closed socket (So is rhs) I think that in both cases we should expect the same behavior. There is the function that does it wrong. I suggest to remove the call to the close() function: AbstractSocket& AbstractSocket::operator=(const AbstractSocket& rhs) { if(&rhs != this) { close(); // <-- this should not happen! copy(rhs); } return *this; } I'm attaching a patch. --- Sent from sourceforge.net because log...@li... is subscribed to https://sourceforge.net/p/log4cplus/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/log4cplus/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |