summaryrefslogtreecommitdiff
path: root/vxi11_server.c
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-11 01:01:08 +0900
committerdaniel <danieruru@gmail.com>2013-01-11 01:01:08 +0900
commit557169f71b442ff10406ed764200f95084816fa8 (patch)
tree430019e4095004d1edad2cd4c38824baa315661c /vxi11_server.c
parent42b2eeebf00d31a1c9c2d62d1aec84b44cf7d258 (diff)
more wiring up
Diffstat (limited to 'vxi11_server.c')
-rw-r--r--vxi11_server.c90
1 files changed, 57 insertions, 33 deletions
diff --git a/vxi11_server.c b/vxi11_server.c
index 02eb966..e852855 100644
--- a/vxi11_server.c
+++ b/vxi11_server.c
@@ -59,6 +59,21 @@ static bool waitForLock(Device_Flags flags, long timeout) {
return false;
}
+static bool waitforio(long timeout) {
+ if (!globals.VxiLocks.command_in_progress)
+ return true;
+ while (timeout < 0 && !globals.VxiLocks.command_in_progress) {
+ usleep(250);
+ timeout -= 250;
+ }
+ if (timeout > 0)
+ return true;
+#ifdef DEBUG
+ printf("timeout waiting for command to finish\n");
+#endif
+ return false;
+}
+
static void lock(int lid) {
globals.VxiLocks.locked_network_server = lid;
}
@@ -90,34 +105,31 @@ create_link_1_svc(Create_LinkParms *argp, struct svc_req *rqstp) {
if (globals.Remote.vxi_connections == MAX_SESSIONS) {
result.error = ERR_OUTOFRESOURCES;
}
+ else if (argp->lockDevice && isLocked() && !waitForLock(FLAG_WAITLOCK, argp->lock_timeout)) {
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ }
else {
- if (argp->lockDevice && isLocked() && !waitForLock(FLAG_WAITLOCK, argp->lock_timeout)) {
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ ActiveLink* link = malloc(sizeof(ActiveLink));
+ if (link == NULL) {
+ result.error = ERR_OUTOFRESOURCES;
}
else {
- ActiveLink* link = malloc(sizeof(ActiveLink));
- if (link == NULL) {
- result.error = ERR_OUTOFRESOURCES;
- }
- else {
-
- int linkid;
- for (linkid = 0; linkid < SIZEOFARRAY(links); linkid++) {
- if (links[linkid] == NULL) {
- links[linkid] = link;
- break;
- }
- }
-
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
- getsockname(rqstp->rq_xprt->xp_sock, (struct sockaddr *) &sin, &len);
- result.error = 0;
- result.abortPort = ntohs(sin.sin_port);
- result.lid = linkid;
- globals.Remote.vxi_connections++;
+ int linkid;
+ for (linkid = 0; linkid < SIZEOFARRAY(links); linkid++) {
+ if (links[linkid] == NULL) {
+ links[linkid] = link;
+ break;
+ }
}
+
+ struct sockaddr_in sin;
+ socklen_t len = sizeof(sin);
+ getsockname(rqstp->rq_xprt->xp_sock, (struct sockaddr *) &sin, &len);
+ result.error = 0;
+ result.abortPort = ntohs(sin.sin_port);
+ result.lid = linkid;
+ globals.Remote.vxi_connections++;
}
}
return &result;
@@ -131,18 +143,21 @@ device_write_1_svc(Device_WriteParms *argp, struct svc_req *rqstp) {
#endif
if (!isValidLink(argp->lid))
result.error = ERR_INVALIDLINKINDENTIFIER;
+ else if (isLocked() && !haveLock(argp->lid) && !waitForLock(argp->flags, argp->lock_timeout))
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else if (!waitforio(argp->io_timeout)) {
+ result.size = 0;
+ result.error = ERR_IOTIMEOUT;
+ }
else {
- if (isLocked() && !haveLock(argp->lid) && !waitForLock(argp->flags, argp->lock_timeout))
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
- else {
#ifdef DEBUG
- printf("got %s on link %d\n", argp->data.data_val, argp->lid);
+ printf("got %s on link %d\n", argp->data.data_val, argp->lid);
#endif
- Parser_main(argp->data.data_val, 0, GPIB_and_VXI_start_query_response, NULL);
- result.size = argp->data.data_len;
- result.error = 0;
- }
+ Parser_main(argp->data.data_val, 0, GPIB_and_VXI_start_query_response, NULL);
+ result.size = argp->data.data_len;
+ result.error = 0;
}
+
return &result;
}
@@ -156,9 +171,18 @@ device_read_1_svc(Device_ReadParms *argp, struct svc_req *rqstp) {
result.error = ERR_INVALIDLINKINDENTIFIER;
else if (isLocked() && !haveLock(argp->lid) && !waitForLock(argp->flags, argp->lock_timeout))
result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else if (!waitforio(argp->io_timeout)) {
+ result.error = ERR_IOTIMEOUT;
+ }
else {
- result.data.data_val = "HELLO!";
- result.data.data_len = 7;
+ if (globals.Registers.pending_output_message != NULL) {
+ result.data.data_val = globals.Registers.pending_output_message;
+ result.data.data_len = strlen(result.data.data_val);
+ }
+ else {
+ result.data.data_val = NULL;
+ result.data.data_len = 0;
+ }
result.error = 0;
result.reason = 0x4;
}