4 * dgram-socket create <local> => <sockid>
5 * dgram-socket close <sockid>
6 * dgram-socket transmit <sockid> <data> <remote>
7 * dgram-socket on-receive <sockid> [<script>]
8 * calls, effectively, eval <script> [list <data> <remote-addr> <socket>]
9 * if script not supplied, cancel
17 static void setobjdataid(Tcl_Obj *o, int ix, IdDataTable *tab) {
20 ulp= TALLOC(sizeof(unsigned long));
22 o->internalRep.twoPtrValue.ptr1= tab;
23 o->internalRep.twoPtrValue.ptr2= ulp;
24 o->typePtr= &tabledataid_nearlytype;
27 int tabledataid_parse(Tcl_Interp *ip, Tcl_Obj *o, IdDataTable *tab) {
32 if (o->typePtr == &tabledataid_nearlytype &&
33 o->internalRep.twoPtrValue.ptr1 == tab) return TCL_OK;
35 l= strlen(tab->prefix);
36 str= Tcl_GetStringFromObj(o,0);
37 if (memcmp(str,tab->prefix,l))
38 return staticerr(ip,"bad id (wrong prefix)",0);
39 errno=0; ul=strtoul(str+l,&ep,10);
40 if (errno || *ep) return staticerr(ip,"bad id number",0);
41 if (ul > INT_MAX) return staticerr(ip,"out of range id number",0);
44 setobjdataid(o,ul,tab);
48 int pat_iddata(Tcl_Interp *ip, Tcl_Obj *o, void **rv, IdDataTable *tab) {
52 rc= tabledataid_parse(ip,o,tab);
55 ix= *(unsigned long*)o->internalRep.twoPtrValue.ptr2;
56 if (ix >= tab->n || !(r= tab->a[ix]))
57 return staticerr(ip,"id not in use",0);
59 assert(*(int*)r == ix);
65 Tcl_Obj *ret_iddata(Tcl_Interp *ip, void *val, IdDataTable *tab) {
66 /* Command procedure implementation may set val->ix,
67 * ie *(int*)val, to -1, to mean it's a new struct. Otherwise
68 * it had better be an old one !
75 for (ix=0; ix<tab->n && tab->a[ix]; ix++);
79 tab->a= (void*)Tcl_Realloc((void*)tab->a, tab->n*sizeof(*tab->a));
80 while (ix<tab->n) tab->a[ix++]=0;
86 assert(val == tab->a[ix]);
90 setobjdataid(o,ix,tab);
91 Tcl_InvalidateStringRep(o);
95 static int tabledataid_nt_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
99 static void tabledataid_nt_free(Tcl_Obj *o) {
100 TFREE(o->internalRep.twoPtrValue.ptr2);
101 o->internalRep.twoPtrValue.ptr2= 0;
104 static void tabledataid_nt_dup(Tcl_Obj *src, Tcl_Obj *dup) {
105 setobjdataid(dup,*(unsigned long*)src->internalRep.twoPtrValue.ptr2,
106 src->internalRep.twoPtrValue.ptr1);
109 static void tabledataid_nt_ustr(Tcl_Obj *o) {
113 prefix= ((IdDataTable*)o->internalRep.twoPtrValue.ptr1)->prefix;
114 snprintf(buf,sizeof(buf), "%lu",
115 *(unsigned long*)o->internalRep.twoPtrValue.ptr2);
116 obj_updatestr_vstringls(o,
117 prefix, strlen(prefix),
122 Tcl_ObjType tabledataid_nearlytype = {
124 tabledataid_nt_free, tabledataid_nt_dup,
125 tabledataid_nt_ustr, tabledataid_nt_sfa