2014.09.14 03:53 AM
#include "k.h"
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
void on_quote()
{
K x = knk(5, ks((S)"AAPL"), kf(100.0), kf(100.0), ki(100), ki(100));
K ret = k(0, (S)".u.upd", ks((S)"quote"), x, (K)NULL);
if(!ret) printf("Socket broken\n");
if(ret->t==-128) printf("Error: %s\n", ret->s);
}
void *event_loop(void *args)
{
while(true)
{
// this would select() from socket
on_quote();
sleep(1);
}
}
extern "C" K listen(K ignore)
{
pthread_t thread;
int rc = pthread_create(&thread, NULL, event_loop, NULL);
if(rc) {
krr((S)"Unable to create thread");
exit(-1);
}
R (K)0;
}
This seems to work alight, but if I subscribe with another client, e.g. q cx.q show I get error message Error: no socket.
Noted that the Bloomberg feed handler utilizes fdevent.h, but since my program should run on OS X as well, this is not an option.
What is the proper way to handle this? I have tried looking at the Reuters feed handler, which uses pthread.h, but I haven't managed to implement it properly.
Many thanks!
2014.09.14 10:27 AM
2014.09.15 04:56 AM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.