0

Given FILE* stream = fdopen(sfd,"r+"), where sfd refers to the file descriptor of a socket, is there any function that takes a FILE* as parameter and is able to shutdown a part of the socket (ie, close the socket for write processes)?

Or, alternatively: Is it safe to use shutdown (as described in shutdown(3)) (preceeded by an invocation of fflush() of course), when I already invoked fdopen on the socket file descriptor? I wasn't able to find the answer in the man pages (nor on the internet).

Thanks.

keezar
  • 83
  • 1
  • 4
  • 1
    `shutdown(fileno(stream), ...);` – user207421 Dec 01 '19 at 19:59
  • @user207421 which is basically the same as `shutdown(sfd,...)`. My question is, if it is legit to invoke `shutdown()` on the file descriptor, since there exists already an associated stream? Could the invocation of `shutdown()` result in undefined behaviour? Thanks. – keezar Dec 02 '19 at 19:52
  • 1
    Not 'basically the same'. *Exactly* the same. But that's what you asked for. The answer to the rest is also 'yes', but yes you need to `fflush()` first. – user207421 Dec 03 '19 at 00:53
  • Alright, thank you! – keezar Dec 03 '19 at 20:27

0 Answers0