summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-10 21:47:42 +0900
committerdaniel <danieruru@gmail.com>2013-01-10 21:47:42 +0900
commit48577c89c567a0d9f6efc88dc03fb94258b17fd5 (patch)
tree5c2cb34e07cfc8621910d464438945851fc393f0
parent0e75195fd93cb3e4eb0c1e29eca11894edf5c076 (diff)
more filling out on the server side
-rw-r--r--CMakeLists.txt1
-rw-r--r--libvxi11client/client.c4
-rw-r--r--libvxi11client/libvxi11client.c8
-rw-r--r--vxi11_server.c265
4 files changed, 198 insertions, 80 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41fbfca..5d34ad6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@ add_executable(instr-daemon instr-daemon.c
vxi11_server.c
vxi11_xdr.c
vxi11_svc.c
+ vxi11_clnt.c
)
add_executable(instr-client instr-client.c)
diff --git a/libvxi11client/client.c b/libvxi11client/client.c
index 816d2f3..04753a8 100644
--- a/libvxi11client/client.c
+++ b/libvxi11client/client.c
@@ -128,10 +128,12 @@ int main(int argc, char *argv[]) {
printf("error unlocking; %s\n", geterrorstring(err));
printf("\n");
- // create interrupt channel
+ // Interrupt channel tests
printf("-- Testing interrupt channel --\n");
+ // create interrupt channel
if ((err = vxi11_create_intr_chan()) > 0) {
printf("Created interrupt channel\n");
+ sleep(10);
// destroy interrupt channel
if ((err = vxi11_destroy_intr_chan()) > 0)
printf("Destroyed interrupt channel\n");
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index cf57f17..2f36147 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -117,7 +117,7 @@ int vxi11_open(char* address, char* device) {
link = linkresp->lid;
#ifdef DEBUG
- printf("Link created, abort channel port %d\n", ntohs(linkresp->abortPort));
+ printf("Link created, lid is %d, abort channel port %d\n", linkresp->lid, linkresp->abortPort);
#endif
struct sockaddr_in serveraddr;
@@ -127,7 +127,7 @@ int vxi11_open(char* address, char* device) {
inet_ntop(AF_INET, &serveraddr.sin_addr, addressstring, sizeof(addressstring));
printf("Remote is %s\n", addressstring);
#endif
- serveraddr.sin_port = linkresp->abortPort;
+ serveraddr.sin_port = htons(linkresp->abortPort);
int sock = RPC_ANYSOCK;
abortclnt = clnttcp_create(&serveraddr, DEVICE_ASYNC, DEVICE_ASYNC_VERSION, &sock, 0, 0);
if (abortclnt == NULL)
@@ -359,7 +359,7 @@ static gpointer interruptthreadfunc(gpointer data) {
fprintf(stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, tcp).\n");
return 0;
}
- *((u_short*) data) = transp->xp_port;
+ *((unsigned int*) data) = transp->xp_port;
int no_of_fds;
int i;
@@ -400,7 +400,7 @@ int vxi11_create_intr_chan() {
return 0;
interruptchannelopen = true;
- u_short port = -1;
+ unsigned int port = -1;
g_thread_init(NULL);
interruptthread = g_thread_create(interruptthreadfunc, &port, true, NULL);
diff --git a/vxi11_server.c b/vxi11_server.c
index 0944b60..b1f7c41 100644
--- a/vxi11_server.c
+++ b/vxi11_server.c
@@ -12,6 +12,8 @@
#include <stdlib.h>
#endif
+#define SIZEOFARRAY(a) (sizeof(a) / sizeof(a[0]))
+
#define ERR_SYNTAXERROR 1
#define ERR_DEVICENOTACCESSIBLE 3
#define ERR_INVALIDLINKINDENTIFIER 4
@@ -27,6 +29,17 @@
#define ERR_ABORT 23
#define ERR_CHANNELALREADYESTABLISHED 29
+static CLIENT* intclient = NULL;
+
+typedef struct {
+} ActiveLink;
+
+static ActiveLink* links[MAX_SESSIONS] = { NULL };
+
+static bool isValidLink(int linkid) {
+ return links[linkid] != NULL;
+}
+
static bool isLocked() {
return globals.VxiLocks.locked_network_server != NO_SERVER_LOCKED;
}
@@ -49,42 +62,77 @@ static void unlock() {
Device_Error *
device_abort_1_svc(Device_Link *argp, struct svc_req *rqstp) {
- printf("device_abort_1_svc()\n");
static Device_Error result;
-
- /*
- * insert server code here
- */
- result.error = 0;
+#ifdef DEBUG
+ printf("device_abort_1_svc()\n");
+#endif
+ if (!isValidLink(*argp))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.error = 0;
+ }
return &result;
}
Create_LinkResp *
create_link_1_svc(Create_LinkParms *argp, struct svc_req *rqstp) {
- printf("create_link_1_svc()\n");
static Create_LinkResp result;
- globals.Remote.vxi_connections++;
- result.error = 0;
-
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
- getsockname(rqstp->rq_xprt->xp_sock, (struct sockaddr *) &sin, &len);
- result.abortPort = sin.sin_port;
+#ifdef DEBUG
+ printf("create_link_1_svc()\n");
+#endif
+ if (globals.Remote.vxi_connections == MAX_SESSIONS) {
+ result.error = ERR_OUTOFRESOURCES;
+ }
+ else {
+ if (argp->lockDevice && isLocked()) {
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ }
+ 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++;
+
+ }
+ }
+ }
return &result;
}
Device_WriteResp *
device_write_1_svc(Device_WriteParms *argp, struct svc_req *rqstp) {
static Device_WriteResp result;
+#ifdef DEBUG
printf("device_write_1_svc()\n");
-
- if (isLocked(argp->lid) && !haveLock(argp->lid))
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
else {
- printf("%s\n", argp->data.data_val);
- //result.size = argp->data.data_len;
- result.size = 1;
- result.error = 0;
+ if (isLocked(argp->lid) && !haveLock(argp->lid))
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else {
+ printf("%s\n", argp->data.data_val);
+ //result.size = argp->data.data_len;
+ result.size = 1;
+ result.error = 0;
+ }
}
return &result;
}
@@ -92,84 +140,120 @@ device_write_1_svc(Device_WriteParms *argp, struct svc_req *rqstp) {
Device_ReadResp *
device_read_1_svc(Device_ReadParms *argp, struct svc_req *rqstp) {
static Device_ReadResp result;
+#ifdef DEBUG
printf("device_read_1_svc()\n");
-
- if (isLocked(argp->lid) && !haveLock(argp->lid))
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
else {
- result.data.data_val = "HELLO!";
- result.data.data_len = 7;
- result.error = 0;
- result.reason = 0x4;
+ if (isLocked(argp->lid) && !haveLock(argp->lid))
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else {
+ result.data.data_val = "HELLO!";
+ result.data.data_len = 7;
+ result.error = 0;
+ result.reason = 0x4;
+ }
}
return &result;
}
Device_ReadStbResp *
device_readstb_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) {
- printf("device_readstb_1_svc()\n");
static Device_ReadStbResp result;
- result.error = 0;
- result.stb = 0;
+#ifdef DEBUG
+ printf("device_readstb_1_svc()\n");
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.error = 0;
+ result.stb = 0;
+ }
return &result;
}
Device_Error *
device_trigger_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) {
- printf("device_trigger_1_svc()\n");
static Device_Error result;
-
- result.error = 0;
+#ifdef DEBUG
+ printf("device_trigger_1_svc()\n");
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.error = 0;
+ }
return &result;
}
Device_Error *
device_clear_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) {
- printf("device_clear_1_svc()\n");
static Device_Error result;
-
- result.error = 0;
+#ifdef DEBUG
+ printf("device_clear_1_svc()\n");
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.error = 0;
+ }
return &result;
}
Device_Error *
device_remote_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("device_remote_1_svc()\n");
-
- if (isLocked() && !haveLock(argp->lid))
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
- else
- result.error = 0;
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ if (isLocked() && !haveLock(argp->lid))
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else
+ result.error = 0;
+ }
return &result;
}
Device_Error *
device_local_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("device_local_1_svc()\n");
-
- if (isLocked() && !haveLock(argp->lid))
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
- else
- result.error = 0;
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ if (isLocked() && !haveLock(argp->lid))
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ else
+ result.error = 0;
+ }
return &result;
}
Device_Error *
device_lock_1_svc(Device_LockParms *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("device_lock_1_svc()\n");
-
- if (isLocked(argp->lid)) {
- result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
- if (haveLock(argp->lid)) {
- // maybe do something here to warn about a device trying to lock multiple times?
- }
- }
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
else {
- lock(argp->lid);
- result.error = 0;
+ if (isLocked(argp->lid)) {
+ result.error = ERR_DEVICELOCKEDBYANOTHERLINK;
+ if (haveLock(argp->lid)) {
+ // maybe do something here to warn about a device trying to lock multiple times?
+ }
+ }
+ else {
+ lock(argp->lid);
+ result.error = 0;
+ }
}
return &result;
}
@@ -177,13 +261,18 @@ device_lock_1_svc(Device_LockParms *argp, struct svc_req *rqstp) {
Device_Error *
device_unlock_1_svc(Device_Link *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("device_unlock_1_svc()\n");
-
- if (!isLocked(*argp) || !haveLock(*argp))
- result.error = ERR_NOLOCKHELDBYTHISLINK;
+#endif
+ if (!isValidLink(*argp))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
else {
- result.error = 0;
- unlock();
+ if (!isLocked(*argp) || !haveLock(*argp))
+ result.error = ERR_NOLOCKHELDBYTHISLINK;
+ else {
+ result.error = 0;
+ unlock();
+ }
}
return &result;
}
@@ -191,42 +280,66 @@ device_unlock_1_svc(Device_Link *argp, struct svc_req *rqstp) {
Device_Error *
device_enable_srq_1_svc(Device_EnableSrqParms *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("device_enable_srq_1_svc()\n");
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.error = 0;
+ }
return &result;
}
Device_DocmdResp *
device_docmd_1_svc(Device_DocmdParms *argp, struct svc_req *rqstp) {
- printf("device_docmd_1_svc()\n");
static Device_DocmdResp result;
- result.data_out.data_out_len = 0;
- result.data_out.data_out_val = NULL;
- result.error = ERR_OPERATIONNOTSUPPORTED;
+#ifdef DEBUG
+ printf("device_docmd_1_svc()\n");
+#endif
+ if (!isValidLink(argp->lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+ result.data_out.data_out_len = 0;
+ result.data_out.data_out_val = NULL;
+ result.error = ERR_OPERATIONNOTSUPPORTED;
+ }
return &result;
}
Device_Error *
destroy_link_1_svc(Device_Link *argp, struct svc_req *rqstp) {
- printf("destroy_link_1_svc()\n");
static Device_Error result;
+#ifdef DEBUG
+ printf("destroy_link_1_svc()\n");
+#endif
+ int lid = *argp;
+ if (!isValidLink(lid))
+ result.error = ERR_INVALIDLINKINDENTIFIER;
+ else {
+#ifdef DEBUG
+ printf("link %d destroyed\n", lid);
+#endif
+ free(links[lid]);
+ links[lid] = NULL;
+ }
+
globals.Remote.vxi_connections--;
return &result;
}
-static bool havechannel = false;
-
Device_Error *
create_intr_chan_1_svc(Device_RemoteFunc *argp, struct svc_req *rqstp) {
static Device_Error result;
- printf("create_intr_chan_1_svc()\n");
-
#ifdef DEBUG
+ printf("create_intr_chan_1_svc()\n");
char clientaddressstring[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &argp->hostAddr, clientaddressstring, sizeof(clientaddressstring));
printf("Client %s is asking for an interrupt connection on port %u\n", clientaddressstring, argp->hostPort);
#endif
-
- if (havechannel) {
+ if (argp->progFamily != DEVICE_TCP || argp->progNum != DEVICE_INTR || argp->progVers != DEVICE_INTR_VERSION)
+ result.error = ERR_OPERATIONNOTSUPPORTED;
+ else if (intclient != NULL) {
result.error = ERR_CHANNELALREADYESTABLISHED;
}
else {
@@ -243,7 +356,7 @@ create_intr_chan_1_svc(Device_RemoteFunc *argp, struct svc_req *rqstp) {
result.error = ERR_CHANNELNOTESTABLISHED;
}
else {
- havechannel = true;
+ intclient = clnt;
result.error = 0;
}
}
@@ -253,12 +366,14 @@ create_intr_chan_1_svc(Device_RemoteFunc *argp, struct svc_req *rqstp) {
Device_Error *
destroy_intr_chan_1_svc(void *argp, struct svc_req *rqstp) {
static Device_Error result;
+#ifdef DEBUG
printf("destroy_intr_chan_1_svc()\n");
- if (!havechannel) {
+#endif
+ if (intclient == NULL) {
result.error = ERR_CHANNELNOTESTABLISHED;
}
else {
- havechannel = false;
+ intclient = NULL;
result.error = 0;
}
return &result;