Writing synchronous function in C

Hi,

I have been using the following line from the manual to receive asynchronous requests from a kdb instance, but was wondering if there was a way to accept and respond to synchronous requests.

r = k(c,(S)0);

Thanks,

Victor

i think it is?

? r = k(-c,(S)0);

but checking the usual documentation will say for sure

To read any type of incoming message

K r=k(c,(S)0); / blocks until a message arrives

Unfortunately, you can send sync/async msgs only using the c-api; you can’t send a response msg (type 2).

Thanks, Charles.  Is there an API where one can send a response to a synchronous call?

You could hack the source for either c# or java.

e.g. (untested)

public c(ServerSocket s)throws IOException
{
  io(s.accept());
  i.read(b=new byte[99]); 
  o.write(b,0,1);
}
c c=new c(new ServerSocket(5010));
while(true)
  c.w(2,c.k()); // echo incoming back with msg type 2 (response type message)

it assumes that the incoming messages are sync requests. The remote end would get confused it you send it response messages that don’t match a sync request. Currently I don’t think the incoming message type is stored, but it can be picked out here

public Object k()throws KException,IOException,UnsupportedEncodingException{synchronized(i){i.readFully(b=new byte[8]);a=b[0]==1;

byte msgType=b[1]; //0 - async, 1 - sync, 2 - response

boolean c=b[2]==1;j=4;i.readFully(b=new byte[ri()-8]);if(c)u();else j=0;if(b[0]==-128){j=1;throw new KException(rs());}return r();}}

For sending an error response

void wErrorResponse(String s)throws IOException

{

    int n=2+ns(s)+8; // space for -128, null terminator and 8 byte header

    synchronized(o)

    {

        B=new byte[n];

        B[0]=0;

        B[1]=2; // response message

        J=4; // write msg length at offset 4

        w(n);

        w((byte)-128);

        w(s);

        o.write(B);

    }

}

Thanks, Charles.  All of this worked splendidly.  The only minor change I had to make was to declare the method w(int i, Object k) public.