nx_world_telemetry_route_probe.nx source
↩ module page · 18 lines · 1129 B
1import "nx_http_post.nx"
2func main(argc:i64,argv:*i64)->i64 {
3 if argc!=6 { return 2 }
4 let sizes:*i64=sys_mmap(16) as *i64
5 let path:*u8=sys_read_file(argv[1] as *u8,sizes); let pn:i64=sizes[0]
6 let body:*u8=sys_read_file(argv[2] as *u8,sizes); let bn:i64=sizes[0]
7 if pn<1 || bn<0 { return 2 }
8 let method:*u8=argv[3] as *u8
9 let wanted:i64=hp_atoi(argv[4] as *u8,0,hp_strlen(argv[4] as *u8))
10 let port:i64=hp_atoi(argv[5] as *u8,0,hp_strlen(argv[5] as *u8))
11 let addr:*u8=sys_mmap(16); nx_http_client_sockaddr_ipv4(addr,127,0,0,1,port)
12 let fd:i64=sys_socket(2,1,0); if fd<0 { return 2 }; if sys_connect(fd,addr,16)<0 { return 2 }
13 let req:*u8=sys_mmap(pn+bn+8192); var rn:i64=0
14 if method[0]==71 as u8 { rn=nx_http_client_build_request(path,pn,"localhost" as *u8,9,req) } else { rn=nx_http_client_build_request_post(path,pn,"localhost" as *u8,9,"application/json" as *u8,16,body,bn,req) }
15 if sys_write(fd,req,rn)!=rn { return 2 }
16 let response:*u8=sys_mmap(65536); let n:i64=hp_drain(fd,response,65536); sys_close(fd); sys_write(1,response,n)
17 if n<12 { return 1 }; if hp_atoi(response,9,3)!=wanted { return 1 }; return 0
18}