Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/file/fdreceiver.cpp
Show All 21 Lines | |||||
22 | #include <errno.h> | 22 | #include <errno.h> | ||
23 | 23 | | |||
24 | #include "sharefd_p.h" | 24 | #include "sharefd_p.h" | ||
25 | #include "fdreceiver.h" | 25 | #include "fdreceiver.h" | ||
26 | 26 | | |||
27 | FdReceiver::FdReceiver(const QString &path, QObject *parent) | 27 | FdReceiver::FdReceiver(const QString &path, QObject *parent) | ||
28 | : QObject(parent) | 28 | : QObject(parent) | ||
29 | , m_readNotifier(nullptr) | 29 | , m_readNotifier(nullptr) | ||
30 | , m_path(path) | ||||
30 | , m_socketDes(-1) | 31 | , m_socketDes(-1) | ||
31 | , m_fileDes(-1) | 32 | , m_fileDes(-1) | ||
32 | { | 33 | { | ||
34 | ::unlink(m_path.toLocal8Bit().constData()); | ||||
35 | | ||||
33 | m_socketDes = ::socket(AF_LOCAL, SOCK_STREAM|SOCK_NONBLOCK, 0); | 36 | m_socketDes = ::socket(AF_LOCAL, SOCK_STREAM|SOCK_NONBLOCK, 0); | ||
34 | if (m_socketDes == -1) { | 37 | if (m_socketDes == -1) { | ||
35 | std::cerr << "socket error:" << strerror(errno) << std::endl; | 38 | std::cerr << "socket error:" << strerror(errno) << std::endl; | ||
36 | return; | 39 | return; | ||
37 | } | 40 | } | ||
38 | 41 | | |||
39 | const SocketAddress addr(path.toStdString()); | 42 | const SocketAddress addr(path.toStdString()); | ||
40 | if (bind(m_socketDes, addr.address(), addr.length()) != 0 || listen(m_socketDes, 5) != 0) { | 43 | if (bind(m_socketDes, addr.address(), addr.length()) != 0 || listen(m_socketDes, 5) != 0) { | ||
ossi: do the first unlink right before here, so it's equivalent with the old code, just better… | |||||
41 | std::cerr << "bind/listen error:" << strerror(errno) << std::endl; | 44 | std::cerr << "bind/listen error:" << strerror(errno) << std::endl; | ||
42 | ::close(m_socketDes); | 45 | ::close(m_socketDes); | ||
43 | m_socketDes = -1; | 46 | m_socketDes = -1; | ||
44 | return; | 47 | return; | ||
45 | } | 48 | } | ||
46 | 49 | | |||
47 | m_readNotifier = new QSocketNotifier(m_socketDes, QSocketNotifier::Read, this); | 50 | m_readNotifier = new QSocketNotifier(m_socketDes, QSocketNotifier::Read, this); | ||
48 | connect(m_readNotifier, &QSocketNotifier::activated, this, &FdReceiver::receiveFileDescriptor); | 51 | connect(m_readNotifier, &QSocketNotifier::activated, this, &FdReceiver::receiveFileDescriptor); | ||
49 | } | 52 | } | ||
50 | 53 | | |||
51 | FdReceiver::~FdReceiver() | 54 | FdReceiver::~FdReceiver() | ||
52 | { | 55 | { | ||
53 | if (m_socketDes >= 0) { | 56 | if (m_socketDes >= 0) { | ||
54 | ::close(m_socketDes); | 57 | ::close(m_socketDes); | ||
55 | } | 58 | } | ||
56 | } | 59 | } | ||
ossi: any particular reason not to use QFile::remove() here as well? | |||||
chinmoyr: I didn't want to include QFile. That's the only reason. | |||||
ossi: uhm, you're still using it in this very line, just differently ;) | |||||
*head-desk* chinmoyr: *head-desk*
I think I have to get my eyes checked. I will change it right away. | |||||
that's a good addition, but it isn't logically part of this patch, because it adds a new feature (cleanup at exit) instead of only refactoring. ossi: that's a good addition, but it isn't logically part of this patch, because it adds a new… | |||||
So shall I commit this change separately right after pushing this patch? Or after all the related patches are pushed? chinmoyr: So shall I commit this change separately right after pushing this patch? Or after all the… | |||||
ossi: the order really doesn't matter here. | |||||
57 | 60 | | |||
58 | bool FdReceiver::isListening() const | 61 | bool FdReceiver::isListening() const | ||
59 | { | 62 | { | ||
60 | return m_socketDes >= 0 && m_readNotifier; | 63 | return m_socketDes >= 0 && m_readNotifier; | ||
61 | } | 64 | } | ||
62 | 65 | | |||
63 | void FdReceiver::receiveFileDescriptor() | 66 | void FdReceiver::receiveFileDescriptor() | ||
64 | { | 67 | { | ||
Show All 14 Lines |
do the first unlink right before here, so it's equivalent with the old code, just better structured.