Hi,
I’m having trouble reading async return message with kdb c interface. http://code.kx.com/wiki/Cookbook/InterfacingWithC. shows the following code
#include"k.h"#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>int main(){ int retval; K x,r; int fd=khp("localhost",9999); // In a production system, check the return value fd_set fds; struct timeval tv; while(1){ tv.tv_sec=5; tv.tv_usec=0; FD_ZERO(&fds); FD_SET(fd,&fds); retval=select(fd+1,&fds,NULL,NULL,&tv); if(retval==-1) perror("select()"),exit(1); else if(retval){ printf("Data is available now.\n"); if(FD_ISSET(fd,&fds)){ x=k(fd,(S)0); printf("%d\n",x->i); } } else printf("No data within five seconds.\n"); } kclose(fd); return 0;}
I changed to the following for windows and VC2013. but I’m not reciving anything. seems like socket problem? I’ve no idea here.
Thanks
JQ
#include <winsock.h>
#include"k.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
int main(){
int retval;
K x, r;
int fd = khp(“localhost”, 5001); // In a production system, check the return value
printf(“%d\n”, fd);
k(-fd, “a:2+1”, (K)0);
k(fd, “a”, (K)0)
fd_set fds;
struct timeval tv;
while (1){
tv.tv_sec = 5;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(fd, &fds);
retval = select(fd + 1, &fds, NULL, NULL, &tv);
if (retval == -1)
perror(“select()”), exit(1);
else if (retval){
printf(“Data is available now.\n”);
if (FD_ISSET(fd, &fds)){
x = k(fd, (S)0);
printf(“%d\n”, x->i);
}
}
else
printf(“No data within five seconds.\n”);
k(fd, “a”, (K)0);
}
kclose(fd);
return 0;
}