/* * Open a connection to an existing kdb+ process. * * If we just have a host and port we call khp from the kdb+ interface. * If we have a host, port, "username:password" we call instead khpu. */ SEXP kx_r_open_connection(SEXP whence) { SEXP result; int connection, port; char *host; int length = GET_LENGTH(whence); if (length < 2) error("Can't connect with so few parameters.."); port = INTEGER_POINTER (VECTOR_ELT(whence, 1))[0]; host = (char*) CHARACTER_VALUE(VECTOR_ELT(whence, 0)); if (2 == length) connection = khp(host, port); else { char *user = (char*) CHARACTER_VALUE(VECTOR_ELT (whence, 2)); connection = khpu(host, port, user); } if (!connection) error("Could not authenticate"); else if (connection < 0) { #ifdef WIN32 char buf[256]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); error(buf); #else error(strerror(errno)); #endif } PROTECT(result = NEW_INTEGER(1)); INTEGER_POINTER(result)[0] = connection; UNPROTECT(1); return result; }
int main() { K y,d; K r; int e=0; char example[10]; printf("Which example do you want to run?\n"); c=khp("localhost",9001); scanf( "%s", &example ); printf( "Example Chosen was %s\n", example ); //example='eg1'; if( strcmp(example,"eg1")==0)(eg1()); if( strcmp(example,"eg2")==0)(eg2()); if( strcmp(example,"eg3")==0)(eg3()); if( strcmp(example,"eg4")==0)(eg4()); if( strcmp(example,"eg5")==0)(eg5()); if( strcmp(example,"eg6")==0)(eg6()); if( strcmp(example,"eg7")==0)(eg7()); if( strcmp(example,"eg8")==0)(eg8()); printf( "Finished example run. Exiting. Hope you had a nice time." ); kclose(c); return 0; }
static int wrap_khp(lua_State* L) { S h=luaL_optstring(L,1,"0"); I p=luaL_optint(L,2,5000); S u=luaL_optstring(L,3,0); I t=luaL_optint(L,4,-1); if(t<0){if(!u)RI(last_connection=khp(h,p));RI(last_connection=khpu(h,p,u));} RI(last_connection=khpun(h,p,u,t)); }
static ErlDrvData gen_q_drv_start(ErlDrvPort port, char* buff) { open_log(); GenQData* d = (GenQData*)genq_alloc(sizeof(GenQData)); d->port = port; d->opts.unix_timestamp_is_q_datetime = 0; d->opts.day_seconds_is_q_time = 0; khp("",-1); LOG("port started %d\n", 0); return (ErlDrvData)d; }
int luaopen_k (lua_State *L) { static const struct luaL_Reg _k [] = { {"khpun",wrap_khp}, {"khpu",wrap_khp}, {"khp",wrap_khp}, {"kclose",wrap_kclose}, {"k",wrap_k}, {"ks",wrap_ks}, {NULL,NULL} }; khp("",-1); luaL_register(L, "k", _k); return 1; }