VxWorks設置FIONBIO的標準方法是使用ioctl()
而不是fcntl()
。對於FIONBIO文檔給這個作爲一個例子,這顯然是不會編譯,因爲on
具有任何數據類型:如何使用ioctl()在VxWorks中的套接字上設置FIONBIO?
on = TRUE;
status = ioctl (sFd, FIONBIO, &on);
我看到周圍的說,使用這樣的事情(淨例如使用其在本質上是相同的):
int on = 1;
ioctl(fd, FIONBIO, &on);
然而,文件說,該原型ioctl()
是ioctl(int, int, int)
,而我得到無法錯誤int*
轉換爲int
。如果我將該值作爲int
傳遞,我只會得到一個致命的內核任務級別異常。
這是我當前的代碼:
int SetBlocking(int sockfd, bool blocking)
{
int nonblock = !blocking;
return ioctl(sockfd, FIONBIO, &nonblock);
}
返回錯誤:
error: invalid conversion from `int*' to `int'
initializing argument 3 of `int ioctl(int, int, int)'
偉大的鏈接!我真的需要它 – nterry 2013-07-09 23:04:25