linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #00528
[Branch ~linuxdcpp-team/linuxdcpp/trunk] Rev 354: Improved error handling for IPC & show really shows the window
Merge authors:
Razzloss (razzloss)
------------------------------------------------------------
revno: 354 [merge]
committer: Razzloss <razzloss@xxxxxxxxx>
branch nick: master
timestamp: Sat 2010-03-13 12:34:57 +0200
message:
Improved error handling for IPC & show really shows the window
modified:
linux/WulforUtil.cc
linux/WulforUtil.hh
linux/mainwindow.cc
linux/wulfor.cc
--
lp:linuxdcpp
https://code.launchpad.net/~linuxdcpp-team/linuxdcpp/trunk
Your team LinuxDC++ Team is subscribed to branch lp:linuxdcpp.
To unsubscribe from this branch go to https://code.launchpad.net/~linuxdcpp-team/linuxdcpp/trunk/+edit-subscription.
=== modified file 'linux/WulforUtil.cc'
--- linux/WulforUtil.cc 2010-03-11 20:15:35 +0000
+++ linux/WulforUtil.cc 2010-03-13 10:34:37 +0000
@@ -372,24 +372,28 @@
return pipePath;
}
-bool WulforUtil::writeIPCCommand(string cmd)
+int WulforUtil::writeIPCCommand(string cmd)
{
- if (cmd.length() < 1)
- return FALSE;
+ if (cmd.empty())
+ return 0;
const std::string pipepath = WulforUtil::getPipePath();
if (cmd[cmd.length() -1] != '\n')
cmd += '\n';
- int fd = open(pipepath.c_str(), O_WRONLY);
+ int fd = open(pipepath.c_str(), O_WRONLY | O_NONBLOCK);
if (fd >= 0)
{
- write(fd, cmd.c_str(), cmd.length());
+ int wrote = write(fd, cmd.c_str(), cmd.length());
close(fd);
- return TRUE;
+ if (wrote < 0)
+ {
+ return wrote;
+ }
+ return wrote;
}
- return FALSE;
+ return errno;
}
bool WulforUtil::profileIsLocked()
=== modified file 'linux/WulforUtil.hh'
--- linux/WulforUtil.hh 2010-03-10 21:37:51 +0000
+++ linux/WulforUtil.hh 2010-03-13 10:34:37 +0000
@@ -68,7 +68,7 @@
static void copyValue_gui(GtkTreeStore* store, GtkTreeIter *fromIter, GtkTreeIter *toIter, int position);
static void registerIcons();
static const std::string& getPipePath();
- static bool writeIPCCommand(std::string cmd);
+ static int writeIPCCommand(std::string cmd);
static const std::string ENCODING_LOCALE;
=== modified file 'linux/mainwindow.cc'
--- linux/mainwindow.cc 2010-03-11 20:40:41 +0000
+++ linux/mainwindow.cc 2010-03-13 10:34:37 +0000
@@ -1325,15 +1325,14 @@
/* Currently this doesn't handle the situation where data is written
* to pipe without newline. Apparently nothing is read in that case
* and onExternalData is called again and again (causing high cpu usage).
- * So I guess the channel should be cleared somehow. Or this crashes (possibly
- * fixed the crash...) */
+ * So I guess the channel should be cleared somehow. */
gchar *str;
gsize len = 0;
gsize termpos = 0;
GIOStatus status = g_io_channel_read_line(source, &str, &len, &termpos, NULL);
if (termpos > 0)
str[termpos] = 0; // replace newline with 0
- dcdebug("MainWindow::onExternalData, from IO Channel: %s (%d)\n", str, len);
+ dcdebug("MainWindow::onExternalData, from IO Channel: %s (%d)\n", str, (int)len);
if (status == G_IO_STATUS_NORMAL && len > 0)
{
// Handle command
@@ -1349,9 +1348,7 @@
}
if (cmd == "show") {
- /* @TODO: Find code which brings the window to current workspace. Instead of just
- * setting it to visible. */
- gtk_widget_show(GTK_WIDGET(mw->window));
+ gtk_window_present(mw->window);
}
else if (cmd == "refresh")
{
=== modified file 'linux/wulfor.cc'
--- linux/wulfor.cc 2010-03-11 20:40:41 +0000
+++ linux/wulfor.cc 2010-03-13 10:34:37 +0000
@@ -53,28 +53,34 @@
if (WulforUtil::profileIsLocked())
{
bool commandGiven = WulforUtil::startArguments.refresh;
+ int retval = 1;
if (WulforUtil::startArguments.refresh)
- WulforUtil::writeIPCCommand("refresh");
+ retval = WulforUtil::writeIPCCommand("refresh");
for (std::vector<std::string>::iterator it = WulforUtil::startArguments.magnets.begin();
- it != WulforUtil::startArguments.magnets.end(); ++it)
+ retval > 0 && it != WulforUtil::startArguments.magnets.end(); ++it)
{
- WulforUtil::writeIPCCommand(std::string("magnet ") + *it);
+ retval = WulforUtil::writeIPCCommand(std::string("magnet ") + *it);
commandGiven = TRUE;
}
for (std::vector<std::string>::iterator it = WulforUtil::startArguments.urls.begin();
- it != WulforUtil::startArguments.urls.end(); ++it)
+ retval > 0 && it != WulforUtil::startArguments.urls.end(); ++it)
{
- WulforUtil::writeIPCCommand(std::string("connect ") + *it);
+ retval = WulforUtil::writeIPCCommand(std::string("connect ") + *it);
commandGiven = TRUE;
}
- if (WulforUtil::startArguments.show)
+ if (retval > 0 && WulforUtil::startArguments.show)
{
return WulforUtil::writeIPCCommand("show");
}
+ if (retval < 0)
+ {
+ std::cout << _("Failed to talk to running LinuxDC++:") << dcpp::Util::translateError(retval) << std::endl;
+ }
+
if (!commandGiven) // If no arguments were given show the profile lock error. Should we make show the default and remove the lock error message?
- { // (@TODO: For that 'show' should really bring the window to visible area instead of just calling gtk_show on it...")
+ {
gtk_init(&argc, &argv);
std::string message = _("Only one instance of LinuxDC++ is allowed per profile");