You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- a dict: [`K xD(K,K);`](capiref.md#xd-create-dictionary)
462
+
- a table from a dict: [`K xT(K);`](capiref.md#xt-table-from-dictionary)
463
+
- a simple table from a keyed table: [`K ktd(K);`](capiref.md#ktd-create-simple-table)
464
+
- a keyed table: [`K knt(J,K);`](capiref.md#knt-create-keyed-table)
464
465
465
466
A dictionary is a K object of type 99. It contains a list of two K objects; the keys and the values. We can use `kK(x)[0]` and `kK(x)[1]` to get these contained data.
466
467
@@ -473,12 +474,12 @@ The following example shows the steps to create a keyed table:
We use the `int khpu(host, port,username)` function to connect to a q server.
514
+
We use the [`int khpu(host, port,username)`](capiref.md#khpu-connect-no-timeout) function to connect to a q server.
514
515
Note you _must_ call `khpu` before generating any q data, and the very first call to `khpu` must not be concurrent to other `khpu` calls.
515
516
To initialize memory without making a connection, use `khp("",-1);`
516
517
517
518
It is highly recommended to use `khpu` and supply a meaningful username, as this will help server administrators identify a user’s connection.
518
519
519
-
The `khp`,`khpu`and `khpun` functions are for use in stand-alone applications only; they are not for use within a q server via a shared library. Hence, to avoid potential confusion, these functions have been removed from more recent releases of q.
520
+
The `khp`,`khpu`, `khpun` and `khpunc` functions are for use in stand-alone applications only; they are not for use within a q server via a shared library. Hence, to avoid potential confusion, these functions have been removed from more recent releases of q.
520
521
521
522
A timeout can be specified with function `khpun`.
522
523
@@ -533,9 +534,9 @@ Return values for `khp`/`khpu`/`khpun` are:
533
534
-2 - timeout(khpun case)
534
535
```
535
536
536
-
Note that with the release of `c.o` with V2.6, `c.o` now tracks the connection type (pre-V2.6, or V2.6+). Hence to close the connection you must call `kclose` (instead of `close` or `closeSocket`) – this will clean up the connection tracking and close the socket.
537
+
Note that with the release of `c.o` with V2.6, `c.o` now tracks the connection type (pre-V2.6, or V2.6+). Hence to close the connection you must call [`kclose`](capiref.md#kclose-disconnect) (instead of `close` or `closeSocket`) – this will clean up the connection tracking and close the socket.
537
538
538
-
The `k` function is used to send messages over the connection. If a positive handle is used then the call is synchronous, otherwise it is an asynchronous call.
539
+
The [`k`](capiref.md#k-evaluate) function is used to send messages over the connection. If a positive handle is used then the call is synchronous, otherwise it is an asynchronous call.
539
540
540
541
```c
541
542
// Connect to a q server on the localhost port 1234.
@@ -551,7 +552,7 @@ Note that the object returned from an async set call must not be passed to `r0`.
551
552
There is no timeout argument for the `k(handle,…,(K)0)` call, but you can use socket timeouts as described below.
552
553
553
554
554
-
## Unix domain sockets
555
+
### Unix domain sockets
555
556
556
557
A Unix domain socket may be requested via the IP address `0.0.0.0`, e.g.
557
558
@@ -560,7 +561,7 @@ int handle=khpu("0.0.0.0",5000,"user:password");
560
561
```
561
562
562
563
563
-
## SSL/TLS
564
+
###SSL/TLS
564
565
565
566
To use this feature, you must link with one of [the `e` libs](#two-sets-of-files).
566
567
@@ -576,7 +577,11 @@ There’s an additional return value for TLS connections, `-3`, which indicates
576
577
577
578
```c
578
579
extern K sslInfo(K x); // returns an error if init fails, or a dict of settings similar to -26!x
Prior to 4.1t 2023.11.10, SSL/TLS connections can be used from the initialization thread only, i.e. the thread which first calls any `khp` function since the start of the application. It can now be used for one-shot synchronous requests.
@@ -590,7 +595,7 @@ int h=khpunc("",-1,"",0,2); // remember to test the return value for -3
590
595
```
591
596
592
597
593
-
## Socket timeouts
598
+
###Socket timeouts
594
599
595
600
There are a number of reasons not to specify or implement timeouts.
596
601
Typically these will be hit at the least convenient of times when under load from e.g. a sudden increase in trading volumes.
@@ -617,7 +622,6 @@ if(c>0) sst(c,30000,45000); // timeout sends with 30s, receives with 45s
617
622
```
618
623
619
624
620
-
621
625
## Bulk transfers
622
626
623
627
A kdb+tick feed handler can send one record at a time, like this
@@ -655,8 +659,8 @@ This example assumes rows with three fields: symbol, price and size.
655
659
656
660
Note the two different directions of error flow below.
657
661
658
-
1. To signal an error from your C code to kdb+ use the function `krr(S)`.
659
-
A utility function `orr(S)` can be used to signal system errors.
662
+
1. To signal an error from your C code to kdb+ use the function [`krr(S)`](capiref.md#krr-signal-c-error).
663
+
A utility function [`orr(S)`](capiref.md#orr-signal-system-error) can be used to signal system errors.
660
664
It is similar to `krr(S)`, but it appends a system error message to the user-provided string before passing it to `krr`.
661
665
662
666
1. To catch an error code from the results of a call to `r=k(h, …)`, check the return value and type.
@@ -672,9 +676,6 @@ if(r && -128==r->t)
672
676
Under some network-error scenarios, `errno` can be used to obtain the details of the error,
673
677
e.g. `perror(“network”);`
674
678
675
-
:fontawesome-regular-hand-point-right:
676
-
[`krr`](capiref.md#krr-signal-c-error)
677
-
678
679
679
680
## Return values
680
681
@@ -702,7 +703,7 @@ K identity(){
702
703
703
704
## Callbacks
704
705
705
-
The `void sd0(I)` and `K sd1(I, K(*)(I))` functions are for use with callbacks and are available only within q itself, i.e. used from a shared library loaded into q.
706
+
The [`void sd0(I)`](capiref.md#sd0-remove-callback) and [`K sd1(I, K(*)(I))`](capiref.md#sd1-set-function-on-loop) functions are for use with callbacks and are available only within q itself, i.e. used from a shared library loaded into q.
706
707
The value of the file descriptor passed to `sd1` must be 0 <`fd`< 1024, and 1021 happens to be the maximum number of supported connections (recalling 0, 1, 2 used for stdin,stdout,stderr).
707
708
708
709
```c
@@ -717,7 +718,7 @@ sd0(d);
717
718
sd0x(d,1);
718
719
```
719
720
720
-
Each of the above calls removes the callback on `d` and calls `kclose(d)`. `sd0x(I d,I f)` was introduced in V3.0 2013.04.04: its second argument indicates whether to call `kclose(d)`.
721
+
Each of the above calls removes the callback on `d` and calls `kclose(d)`. [`sd0x(I d,I f)`](capiref.md#sd0x-remove-callback-conditional) was introduced in V3.0 2013.04.04: its second argument indicates whether to call `kclose(d)`.
721
722
722
723
On Linux, `eventfd` can be used with `sd1` and `sd0`. Given a file efd.c
723
724
@@ -766,32 +767,13 @@ Callbacks from `sd1` are executed on the main thread of q, in the handle context
766
767
767
768
## Serialization and deserialization
768
769
769
-
The `K b9(I,K)` and `K d9(K)` functions serialize and deserialize K objects.
770
-
771
-
```c
772
-
b9(mode,kObject);
773
-
```
770
+
The [`K b9(I,K)`](capiref.md#b9-serialize) and [`K d9(K)`](capiref.md#d9-deserialize) functions serialize and deserialize K objects.
774
771
775
-
will generate a K byte vector that contains the serialized data for `kObject`.
772
+
`b9`will generate a K byte vector that contains the serialized data.
776
773
Since V3.0, for shared libraries loaded into q the value for `mode` must be -1.
777
-
For standalone applications binding with c.o/c.dll, or shared libraries prior to V3.0, the values for `mode` can be
778
-
779
-
value | effect
780
-
------|------
781
-
-1 | valid for V3.0+ for serializing/deserializing within the same process
782
-
0 | unenumerate, block serialization of timespan and timestamp (For working with versions prior to 2.6).
783
-
1 | retain enumerations, allow serialization of timespan and timestamp. (Useful for passing data between threads).
784
-
2 | unenumerate, allow serialization of timespan and timestamp
785
-
3 | unenumerate, compress, allow serialization of timespan and timestamp
786
-
4 | (reserved)
787
-
5 | allow 1TB msgs, but no single vector may exceed 2 billion items
788
-
6 | allow 1TB msgs, and individual vectors may exceed 2 billion items
774
+
For standalone applications binding with c.o/c.dll, or shared libraries prior to V3.0, the values for `mode` can be viewed [here](capiref.md#b9-serialize).
789
775
790
-
```c
791
-
d9(kObject);
792
-
```
793
-
794
-
will deserialize the byte stream in `kObject` returning a new `kObject`.
776
+
`d9` will deserialize the provided byte stream returning a new `kObject`.
795
777
The byte stream passed to `d9` is not altered in any way.
796
778
If you are concerned that the byte vector that you wish to deserialize may be corrupted, call `okx` to verify it is well formed first.
797
779
@@ -811,29 +793,42 @@ else
811
793
812
794
## Miscellaneous
813
795
814
-
The `K dot(K x, K y)` function is the same as the q function `.[x;y]`.
796
+
The [`K dot(K x, K y)`](capiref.md#dot-apply) function is the same as the q function `.[x;y]`.
815
797
816
798
```q
817
799
q).[{x+y};(1 2;3 4)]
818
800
4 6
819
801
```
820
802
821
-
The dynamic link, `K dl(V* f, I n)`, function takes a C function that would take _n_ K objects as arguments and return a new K object, and returns a q function.
803
+
The dynamic link, [`K dl(V* f, I n)`](capiref.md#dl-dynamic-link), function takes a C function that would take _n_ K objects as arguments and return a new K object, and returns a q function.
822
804
It is useful, for example, to expose more than one function from an extension module.
0 commit comments