Commit 94f91b8a authored by sletz's avatar sletz
Browse files

New SetBlocking method for JackSocket.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2110 0c269be4-1314-0410-8aa9-9f06e86f4224
parent f04c8741
......@@ -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.
......
......@@ -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)
{}
};
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -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);
};
/*!
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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
......
......@@ -44,7 +44,7 @@ void JackMachServerNotifyChannel::Close()
//fClientPort.DisconnectPort(); pas ncessaire car le JackMachServerChannel a dja 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) {
......
......@@ -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
......
......@@ -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) {
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment