Using the neon library wrote the code:

ne_uri uri; ne_uri_parse("http://192.168.1.160:80", &uri); ne_inet_addr* inet_addr = ne_iaddr_parse(uri.host, ne_iaddr_ipv4); ne_sock_init(); ne_socket* socket = ne_sock_create(); if(ne_sock_connect(socket, inet_addr, uri.port)){ fprintf(stdout, "Socket failed: %s\n", ne_sock_error(socket)); ne_iaddr_free(inet_addr); ne_uri_free(&uri); ne_sock_exit(); exit(1); } ne_session* session = ne_session_create(uri.scheme, uri.host, uri.port); res = ne_mkcol(session, "/index"); ... 

I launched a test server on a local network at http://192.160.1.160:80. When I start the program, I get:

 Start Socket failed: Too many open files 

I can not understand why I can not connect.

 sysctl -a | grep maxfile kern.maxfiles: 191353 kern.maxfilesperproc: 172215 ulimit -a cpu time (seconds, -t) unlimited file size (512-blocks, -f) unlimited data seg size (kbytes, -d) 33554432 stack size (kbytes, -s) 524288 core file size (512-blocks, -c) unlimited max memory size (kbytes, -m) unlimited locked memory (kbytes, -l) 64 max user processes (-u) 10227 open files (-n) 172215 virtual mem size (kbytes, -v) unlimited swap limit (kbytes, -w) unlimited socket buffer size (bytes, -b) unlimited pseudo-terminals (-p) unlimited kqueues (-k) unlimited umtx shared locks (-o) unlimited 
  • Try to lay out here the code of the minimum complete example (you can see, for 5 hours no one wanted to go into git) - avp
  • one
    @avp, I went off :) I saw that this message is displayed when an error occurs in this line . I figured that first I would have to get up on it in the debugger and look at the arguments, and before that add a couple of debugging conclusions ... Then the phrase "work for the author" surfaced in my head and interest disappeared :) - PinkTux
  • Try resetting errno at the beginning and check the results of calls to all ne_... - avp
  • I am mastering a bit of gdb. I noticed that the functions for some reason get hung up. Everything from ne_uri_parse to ne_sock_connect is repeated many times. Added char ch[256]; printf("%s\n", ne_iaddr_print(inet_addr, ch, sizeof(ch))); char ch[256]; printf("%s\n", ne_iaddr_print(inet_addr, ch, sizeof(ch))); launched ./test > t received a file containing more than 17 thousand such lines 192.168.1.160 - Alexander Troinin

1 answer 1

The problem was the name of the function. connect () I wrote conflicted with the function from the standard posix connect

 int connect(int socket, const struct sockaddr *address, socklen_t address_len) 

The neon library uses the posix standard and the connect function is used to establish a connection (otherwise nothing expected from it). With this, my program also has the name of the connect function and when calling the ne_sock_connect(...) function, it called the connect(...) function not <sys/socket.h> , but my "webdav.h" file and the program went into recursion until the system resources ran out.

By giving the function another name, the problem immediately disappeared.

PS After that I began to miss the namespace of the pros. XD