summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsletz <sletz@0c269be4-1314-0410-8aa9-9f06e86f4224>2008-03-31 14:08:33 +0000
committersletz <sletz@0c269be4-1314-0410-8aa9-9f06e86f4224>2008-03-31 14:08:33 +0000
commit94f91b8a6cccff9dc6c60deacbd79e06422e7b7c (patch)
tree80b6ef16fa26cd2803c3ad6007b8903124fdb647
parentf04c874153ec9993b5206cfdc16da9a9fbf23e6a (diff)
downloadjack2-94f91b8a6cccff9dc6c60deacbd79e06422e7b7c.tar.gz
New SetBlocking method for JackSocket.
git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2110 0c269be4-1314-0410-8aa9-9f06e86f4224
-rw-r--r--ChangeLog4
-rw-r--r--common/JackChannel.h4
-rw-r--r--common/JackEngine.cpp8
-rw-r--r--common/JackSocket.cpp27
-rw-r--r--common/JackSocket.h3
-rw-r--r--common/JackSocketNotifyChannel.cpp1
-rw-r--r--common/JackSocketServerNotifyChannel.cpp3
-rw-r--r--common/JackSocketServerNotifyChannel.h2
-rw-r--r--macosx/JackMachServerNotifyChannel.cpp2
-rw-r--r--macosx/JackMachServerNotifyChannel.h2
-rw-r--r--windows/JackWinNamedPipeServerNotifyChannel.cpp2
-rw-r--r--windows/JackWinNamedPipeServerNotifyChannel.h2
12 files changed, 40 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c8e6655..cdd6f9ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,10 @@ Fernando Lopez-Lezcano
Jackdmp changes log
---------------------------
+2008-03-31 Stephane Letz <letz@grame.fr>
+
+ * New SetBlocking method for JackSocket.
+
2008-03-29 Stephane Letz <letz@grame.fr>
* Correct a missing parameter in the usage message of jack_midiseq.
diff --git a/common/JackChannel.h b/common/JackChannel.h
index 83d44e7f..793d9ec0 100644
--- a/common/JackChannel.h
+++ b/common/JackChannel.h
@@ -201,9 +201,9 @@ class JackServerNotifyChannelInterface
virtual void Close()
{}
- virtual void ClientNotify(int refnum, int notify, int value)
+ virtual void Notify(int refnum, int notify, int value)
{}
-
+
};
diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp
index b0ded321..23561c6f 100644
--- a/common/JackEngine.cpp
+++ b/common/JackEngine.cpp
@@ -134,7 +134,7 @@ void JackEngine::ProcessNext(jack_time_t callback_usecs)
{
fLastSwitchUsecs = callback_usecs;
if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state
- fChannel->ClientNotify(ALL_CLIENTS, kGraphOrderCallback, 0);
+ fChannel->Notify(ALL_CLIENTS, kGraphOrderCallback, 0);
fSignal->SignalAll(); // Signal for threads waiting for next cycle
}
@@ -191,12 +191,12 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions
if (status != NotTriggered && status != Finished) {
jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client->GetClientControl()->fName, status);
- fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
+ fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
}
if (status == Finished && (long)(finished_date - callback_usecs) > 0) {
jack_error("JackEngine::XRun: client %s finished after current callback", client->GetClientControl()->fName);
- fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
+ fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
}
}
}
@@ -272,7 +272,7 @@ void JackEngine::NotifyXRun(jack_time_t callback_usecs)
{
// Use the audio thread => request thread communication channel
fEngineControl->ResetFrameTime(callback_usecs);
- fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0);
+ fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0);
}
void JackEngine::NotifyXRun(int refnum)
diff --git a/common/JackSocket.cpp b/common/JackSocket.cpp
index f7ca839b..b5c890a9 100644
--- a/common/JackSocket.cpp
+++ b/common/JackSocket.cpp
@@ -33,7 +33,7 @@ void JackClientSocket::SetReadTimeOut(long sec)
timout.tv_sec = sec;
timout.tv_usec = 0;
if (setsockopt(fSocket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timout, sizeof(timeval)) < 0) {
- jack_log("setsockopt SO_RCVTIMEO fd = %ld err = %s", fSocket, strerror(errno));
+ jack_error("SetReadTimeOut fd = %ld err = %s", fSocket, strerror(errno));
}
}
@@ -43,7 +43,15 @@ void JackClientSocket::SetWriteTimeOut(long sec)
timout.tv_sec = sec ;
timout.tv_usec = 0;
if (setsockopt(fSocket, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timout, sizeof(timeval)) < 0) {
- jack_log("setsockopt SO_SNDTIMEO fd = %ld err = %s", fSocket, strerror(errno));
+ jack_error("SetWriteTimeOut fd = %ld err = %s", fSocket, strerror(errno));
+ }
+}
+
+void JackClientSocket::SetBlocking(bool onoff)
+{
+ int flag = (onoff) ? 1 : 0;
+ if (ioctl(fSocket, FIONBIO, &flag) < 0) {
+ jack_error("SetBlocking fd = %ld err = %s", fSocket, strerror(errno));
}
}
@@ -120,13 +128,11 @@ int JackClientSocket::Close()
int JackClientSocket::Read(void* data, int len)
{
- int len1;
-
- if ((len1 = read(fSocket, data, len)) != len) {
+ if (read(fSocket, data, len) != len) {
jack_error("Cannot read socket fd = %d err = %s", fSocket, strerror(errno));
if (errno == EWOULDBLOCK) {
- jack_log("JackClientSocket::Read time out");
- return 0;
+ jack_error("JackClientSocket::Read time out");
+ return 0; // For a non blocking socket, a read failure is not considered as an error
} else {
return -1;
}
@@ -139,7 +145,12 @@ int JackClientSocket::Write(void* data, int len)
{
if (write(fSocket, data, len) != len) {
jack_error("Cannot write socket fd = %ld err = %s", fSocket, strerror(errno));
- return -1;
+ if (errno == EWOULDBLOCK) {
+ jack_log("JackClientSocket::Write time out");
+ return 0; // For a non blocking socket, a write failure is not considered as an error
+ } else {
+ return -1;
+ }
} else {
return 0;
}
diff --git a/common/JackSocket.h b/common/JackSocket.h
index ef2ae789..ebcaebc2 100644
--- a/common/JackSocket.h
+++ b/common/JackSocket.h
@@ -25,6 +25,7 @@ Copyright (C) 2004-2008 Grame
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/ioctl.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <errno.h>
@@ -67,6 +68,8 @@ class JackClientSocket : public JackChannelTransaction
}
void SetReadTimeOut(long sec);
void SetWriteTimeOut(long sec);
+
+ void SetBlocking(bool onoff);
};
/*!
diff --git a/common/JackSocketNotifyChannel.cpp b/common/JackSocketNotifyChannel.cpp
index 43001e43..b02b2546 100644
--- a/common/JackSocketNotifyChannel.cpp
+++ b/common/JackSocketNotifyChannel.cpp
@@ -35,6 +35,7 @@ int JackSocketNotifyChannel::Open(const char* name)
jack_error("Cannot connect client socket");
return -1;
}
+
// Use a time out for notifications
fNotifySocket.SetReadTimeOut(SOCKET_TIME_OUT);
return 0;
diff --git a/common/JackSocketServerNotifyChannel.cpp b/common/JackSocketServerNotifyChannel.cpp
index aff52233..1f3d36d1 100644
--- a/common/JackSocketServerNotifyChannel.cpp
+++ b/common/JackSocketServerNotifyChannel.cpp
@@ -31,6 +31,7 @@ int JackSocketServerNotifyChannel::Open(const char* server_name)
jack_error("Cannot connect to server socket");
return -1;
} else {
+ fRequestSocket.SetBlocking(true);
return 0;
}
}
@@ -46,7 +47,7 @@ Can the write operation block?
A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise
(since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...)
*/
-void JackSocketServerNotifyChannel::ClientNotify(int refnum, int notify, int value)
+void JackSocketServerNotifyChannel::Notify(int refnum, int notify, int value)
{
JackClientNotificationRequest req(refnum, notify, value);
if (req.Write(&fRequestSocket) < 0) {
diff --git a/common/JackSocketServerNotifyChannel.h b/common/JackSocketServerNotifyChannel.h
index f5aba2f1..3c29668d 100644
--- a/common/JackSocketServerNotifyChannel.h
+++ b/common/JackSocketServerNotifyChannel.h
@@ -46,7 +46,7 @@ class JackSocketServerNotifyChannel : public JackServerNotifyChannelInterface
int Open(const char* server_name);
void Close();
- void ClientNotify(int refnum, int notify, int value);
+ void Notify(int refnum, int notify, int value);
};
} // end of namespace
diff --git a/macosx/JackMachServerNotifyChannel.cpp b/macosx/JackMachServerNotifyChannel.cpp
index 0b38622d..cdf9ce74 100644
--- a/macosx/JackMachServerNotifyChannel.cpp
+++ b/macosx/JackMachServerNotifyChannel.cpp
@@ -44,7 +44,7 @@ void JackMachServerNotifyChannel::Close()
//fClientPort.DisconnectPort(); pas nŽcessaire car le JackMachServerChannel a dŽja disparu?
}
-void JackMachServerNotifyChannel::ClientNotify(int refnum, int notify, int value)
+void JackMachServerNotifyChannel::Notify(int refnum, int notify, int value)
{
kern_return_t res = rpc_jack_client_rt_notify(fClientPort.GetPort(), refnum, notify, value, 0);
if (res != KERN_SUCCESS) {
diff --git a/macosx/JackMachServerNotifyChannel.h b/macosx/JackMachServerNotifyChannel.h
index d2ffe0cd..21fc216c 100644
--- a/macosx/JackMachServerNotifyChannel.h
+++ b/macosx/JackMachServerNotifyChannel.h
@@ -47,7 +47,7 @@ class JackMachServerNotifyChannel : public JackServerNotifyChannelInterface
int Open(const char* server_name); // Open the Server/Client connection
void Close(); // Close the Server/Client connection
- void ClientNotify(int refnum, int notify, int value);
+ void Notify(int refnum, int notify, int value);
};
} // end of namespace
diff --git a/windows/JackWinNamedPipeServerNotifyChannel.cpp b/windows/JackWinNamedPipeServerNotifyChannel.cpp
index f7e72eba..7f2f14cf 100644
--- a/windows/JackWinNamedPipeServerNotifyChannel.cpp
+++ b/windows/JackWinNamedPipeServerNotifyChannel.cpp
@@ -46,7 +46,7 @@ Can the write operation block?
A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise
(since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...)
*/
-void JackWinNamedPipeServerNotifyChannel::ClientNotify(int refnum, int notify, int value)
+void JackWinNamedPipeServerNotifyChannel::Notify(int refnum, int notify, int value)
{
JackClientNotificationRequest req(refnum, notify, value);
if (req.Write(&fRequestPipe) < 0) {
diff --git a/windows/JackWinNamedPipeServerNotifyChannel.h b/windows/JackWinNamedPipeServerNotifyChannel.h
index 2d8183f0..048faefd 100644
--- a/windows/JackWinNamedPipeServerNotifyChannel.h
+++ b/windows/JackWinNamedPipeServerNotifyChannel.h
@@ -46,7 +46,7 @@ class JackWinNamedPipeServerNotifyChannel : public JackServerNotifyChannelInterf
int Open(const char* server_name);
void Close();
- void ClientNotify(int refnum, int notify, int value);
+ void Notify(int refnum, int notify, int value);
};
} // end of namespace