158 |
send(hSocket, cmd.c_str(), cmd.length(), 0); |
send(hSocket, cmd.c_str(), cmd.length(), 0); |
159 |
} |
} |
160 |
|
|
161 |
// wait until LSCP server answers with a single line answer (throws LinuxSamplerException if optional timeout exceeded) |
// wait until LSCP server answers with a single line answer (throws LinuxSampler::Exception if optional timeout exceeded) |
162 |
string LSCPTest::receiveSingleLineAnswerFromLSCPServer(uint timeout_seconds) throw (LinuxSamplerException) { |
string LSCPTest::receiveSingleLineAnswerFromLSCPServer(uint timeout_seconds) throw (Exception) { |
163 |
string msg = receiveAnswerFromLSCPServer("\n", timeout_seconds); |
string msg = receiveAnswerFromLSCPServer("\n", timeout_seconds); |
164 |
// remove carriage return characters |
// remove carriage return characters |
165 |
string::size_type p = msg.find('\r'); |
string::size_type p = msg.find('\r'); |
170 |
return msg.substr(0, pos); |
return msg.substr(0, pos); |
171 |
} |
} |
172 |
|
|
173 |
/// wait until LSCP server answers with a multi line answer (throws LinuxSamplerException if optional timeout exceeded) |
/// wait until LSCP server answers with a multi line answer (throws LinuxSampler::Exception if optional timeout exceeded) |
174 |
vector<string> LSCPTest::receiveMultiLineAnswerFromLSCPServer(uint timeout_seconds) throw (LinuxSamplerException) { |
vector<string> LSCPTest::receiveMultiLineAnswerFromLSCPServer(uint timeout_seconds) throw (Exception) { |
175 |
string msg = receiveAnswerFromLSCPServer("\n.\r\n", timeout_seconds); |
string msg = receiveAnswerFromLSCPServer("\n.\r\n", timeout_seconds); |
176 |
return __ConvertMultiLineMessage(msg); |
return __ConvertMultiLineMessage(msg); |
177 |
} |
} |
181 |
while (recv(hSocket, &c, 1, 0) > 0); |
while (recv(hSocket, &c, 1, 0) > 0); |
182 |
} |
} |
183 |
|
|
184 |
/// wait until LSCP server answers with the given \a delimiter token at the end (throws LinuxSamplerException if optional timeout exceeded or socket error occured) |
/// wait until LSCP server answers with the given \a delimiter token at the end (throws LinuxSampler::Exception if optional timeout exceeded or socket error occured) |
185 |
string LSCPTest::receiveAnswerFromLSCPServer(string delimiter, uint timeout_seconds) throw (LinuxSamplerException) { |
string LSCPTest::receiveAnswerFromLSCPServer(string delimiter, uint timeout_seconds) throw (Exception) { |
186 |
string message; |
string message; |
187 |
char c; |
char c; |
188 |
fd_set sockSet; |
fd_set sockSet; |
196 |
timeout.tv_usec = 0; |
timeout.tv_usec = 0; |
197 |
int res = select(hSocket + 1, &sockSet, NULL, NULL, &timeout); |
int res = select(hSocket + 1, &sockSet, NULL, NULL, &timeout); |
198 |
if (!res) { // if timeout exceeded |
if (!res) { // if timeout exceeded |
199 |
if (!message.size()) throw LinuxSamplerException("LSCPTest::receiveAnswerFromLSCPServer(): timeout (" + ToString(timeout_seconds) + "s) exceeded, no answer received"); |
if (!message.size()) throw Exception("LSCPTest::receiveAnswerFromLSCPServer(): timeout (" + ToString(timeout_seconds) + "s) exceeded, no answer received"); |
200 |
else throw LinuxSamplerException("LSCPTest::receiveAnswerFromLSCPServer(): timeout (" + ToString(timeout_seconds) + "s) exceeded waiting for expected answer (end), received answer: \'" + message + "\'"); |
else throw Exception("LSCPTest::receiveAnswerFromLSCPServer(): timeout (" + ToString(timeout_seconds) + "s) exceeded waiting for expected answer (end), received answer: \'" + message + "\'"); |
201 |
} |
} |
202 |
else if (res < 0) { |
else if (res < 0) { |
203 |
throw LinuxSamplerException("LSCPTest::receiveAnswerFromLSCPServer(): select error"); |
throw Exception("LSCPTest::receiveAnswerFromLSCPServer(): select error"); |
204 |
} |
} |
205 |
} |
} |
206 |
|
|
207 |
// there's something to read, so read one character |
// there's something to read, so read one character |
208 |
int res = recv(hSocket, &c, 1, 0); |
int res = recv(hSocket, &c, 1, 0); |
209 |
if (!res) throw LinuxSamplerException("LSCPTest::receiveAnswerFromLSCPServer(): connection to LSCP server closed"); |
if (!res) throw Exception("LSCPTest::receiveAnswerFromLSCPServer(): connection to LSCP server closed"); |
210 |
else if (res < 0) { |
else if (res < 0) { |
211 |
switch(errno) { |
switch(errno) { |
212 |
case EBADF: |
case EBADF: |
213 |
throw LinuxSamplerException("The argument s is an invalid descriptor"); |
throw Exception("The argument s is an invalid descriptor"); |
214 |
case ECONNREFUSED: |
case ECONNREFUSED: |
215 |
throw LinuxSamplerException("A remote host refused to allow the network connection (typically because it is not running the requested service)."); |
throw Exception("A remote host refused to allow the network connection (typically because it is not running the requested service)."); |
216 |
case ENOTCONN: |
case ENOTCONN: |
217 |
throw LinuxSamplerException("The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2))."); |
throw Exception("The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2))."); |
218 |
case ENOTSOCK: |
case ENOTSOCK: |
219 |
throw LinuxSamplerException("The argument s does not refer to a socket."); |
throw Exception("The argument s does not refer to a socket."); |
220 |
case EAGAIN: |
case EAGAIN: |
221 |
continue; |
continue; |
222 |
//throw LinuxSamplerException("The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received."); |
//throw Exception("The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received."); |
223 |
case EINTR: |
case EINTR: |
224 |
throw LinuxSamplerException("The receive was interrupted by delivery of a signal before any data were available."); |
throw Exception("The receive was interrupted by delivery of a signal before any data were available."); |
225 |
case EFAULT: |
case EFAULT: |
226 |
throw LinuxSamplerException("The receive buffer pointer(s) point outside the process's address space."); |
throw Exception("The receive buffer pointer(s) point outside the process's address space."); |
227 |
case EINVAL: |
case EINVAL: |
228 |
throw LinuxSamplerException("Invalid argument passed."); |
throw Exception("Invalid argument passed."); |
229 |
case ENOMEM: |
case ENOMEM: |
230 |
throw LinuxSamplerException("Could not allocate memory for recvmsg."); |
throw Exception("Could not allocate memory for recvmsg."); |
231 |
default: |
default: |
232 |
throw LinuxSamplerException("Unknown recv() error."); |
throw Exception("Unknown recv() error."); |
233 |
} |
} |
234 |
} |
} |
235 |
|
|