# + tak sie kompiluje: # tclkit ~/tcl/kit/critcl.kit -lib sockopt_lib.tcl # + dostarczane cmd, 31.01.2021 # fileno, setsockopt_tos, getsockopt_tos # + tcl api docs; Tcl_GetChannel i Tcl_GetChannelHandle # http://www.tcl.tk/man/tcl8.6/TclLib/OpenFileChnl.htm # http://www.tcl.tk/man/tcl8.6/TclLib/CrtChannel.htm # package re critcl critcl::ccode { #include #include //#include #include #include //#include #include } critcl::cproc fileno {Tcl_Interp* in char* str} int { Tcl_Channel ch; int desc, err; ch=Tcl_GetChannel(in, str, 0); if (ch==0) {return -1;} err=Tcl_GetChannelHandle(ch, TCL_READABLE , &desc); if (err!=TCL_OK) {err=Tcl_GetChannelHandle(ch, TCL_WRITABLE , &desc); } if (err!=TCL_OK) {return -1;} return desc; } critcl::cproc getsockopt_tos {Tcl_Interp* in int desk} int { int buf=0, ret=0, len; len=sizeof(buf); ret=getsockopt(desk, IPPROTO_IP, IP_TOS, (void*)&buf, (void*)&len); if (ret==-1) {buf=-1; perror("critcl/getsockopt");} return buf; } critcl::cproc setsockopt_tos {Tcl_Interp* in int desk int val} int { int ret,ret2=0; char b=val; ret=setsockopt(desk, IPPROTO_IP, IP_TOS, (const void*)&b, sizeof(b)); if (ret==-1) {ret2=errno; perror("critcl/setsockopt");} return ret2; }