Porting ioctl () calls from unix to linux, error with FIONBIO

I want to use ioctl () to get the number of bytes ready to read

how i did it:

mysocket=socket(....); ioctl(mysocket, FIONBIO, &zero); connect(.....); ioctl( mysocket, FIONREAD, &numBytes ); read(mysocket, buffer, numBytes); 

this works fine on unix, now i need to port it to linux i keep getting error

error: "FIONBIO" was not declared in this area

Is there any header file for linux? or does "FIOBIO" not work at all on Linux?

I have the following headers:

 #include <cstring> #include <sys/socket.h> #include <stropts.h> #include <fcntl.h> #include <stddef.h> #include <sys/un.h> #include <sys/types.h> #include <stdlib.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <sys/select.h> #include <fstream> 

and I deleted

 #include <sys/filio.h> 

since he was throwing errors saying that sys / filio.h was not found

+4
source share
1 answer

Have you tried turning on sys / ioctl.h ?

This code works for me:

 #include <sys/ioctl.h> #include <stdio.h> int main() { printf("FIONBIO value %d\n", FIONBIO); } 

When I execute grep -R FIONBIO /usr/include , it is here:

 /usr/include/asm-generic/ioctls.h:#define FIONBIO 0x5421 
+14
source

Source: https://habr.com/ru/post/1400292/


All Articles