-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to the C example #5
base: main
Are you sure you want to change the base?
Conversation
…rtable manner and by falling back to TCP if used on a system that does not support Multipath TCP
… and fall back to TCP if Multipath TCP is not supported on this system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the new update!
Some suggestions here and one sentence that looks wrong.
|
||
The [simple project](mptcphello.c) in this repository also illustrates how to automatically check with autoconf whether the compilation is on a Multipath TCP enabled host, see [configure.ac](configure.ac) | ||
Most networked applications abstract the creation of a TCP socket in a specific function that is called instead of calling [socket()](https://www.man7.org/linux/man-pages/man3/socket.3p.html) directly. This is a good opportunity to make the code portable and useable on hosts that support Multipath TCP or not. In practice, to efficiently enable Multipath TCP, your code should try to use Multipath TCP when creating the first TCP socket. If this socket is successfully created, then Multipath TCP is enabled on the host and you can continue to use Multipath TCP. Otherwise, the application is running on a host that does not yet support Multipath TCP. In this unfortunate case, you should fall back to regular TCP and always create TCP sockets. You might print an error message to encourage the user to upgrade his/her system to support Multipath TCP... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand the first sentence in this line here. I think some words are missing. Maybe:
In most network applications abstract, the creation of a TCP socket in a specific function is called instead of calling [socket()](https://www.man7.org/linux/man-pages/man3/socket.3p.html) directly.
@@ -1,15 +1,17 @@ | |||
# Using Multipath TCP in C | |||
|
|||
|
|||
It is pretty simple to use Multipath TCP with the C language. You simply need to pass IPPROTO_MPTCP as the third argument of the [socket()](https://www.man7.org/linux/man-pages/man3/socket.3p.html) system call. Make sure that IPPROTO_MPTCP is correctly defined and if you, define it as follows : | |||
It is pretty simple to use Multipath TCP with the C language. You simply need to pass IPPROTO_MPTCP as the third argument of the [socket()](https://www.man7.org/linux/man-pages/man3/socket.3p.html) system call. Make sure that IPPROTO_MPTCP is correctly defined and if not, define it as follows : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(do not hesitate to add backquotes around IPPROTO_MPTCP
and any other non English words or non capitalised names)
The [simple project](mptcphello.c) in this repository also illustrates how to automatically check with autoconf whether the compilation is on a Multipath TCP enabled host, see [configure.ac](configure.ac) | ||
Most networked applications abstract the creation of a TCP socket in a specific function that is called instead of calling [socket()](https://www.man7.org/linux/man-pages/man3/socket.3p.html) directly. This is a good opportunity to make the code portable and useable on hosts that support Multipath TCP or not. In practice, to efficiently enable Multipath TCP, your code should try to use Multipath TCP when creating the first TCP socket. If this socket is successfully created, then Multipath TCP is enabled on the host and you can continue to use Multipath TCP. Otherwise, the application is running on a host that does not yet support Multipath TCP. In this unfortunate case, you should fall back to regular TCP and always create TCP sockets. You might print an error message to encourage the user to upgrade his/her system to support Multipath TCP... | ||
|
||
The [simple project](mptcphello.c) in this repository illustrates this strategy. If you want to automatically check with autoconf whether the compilation is on a Multipath TCP enabled host, see [configure.ac](configure.ac) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the configure.ac
, I would put big warnings to avoid doing that at compilation time except maybe to simplify tests (and still, I don't think it is a good idea to do that at the compilation time, even for tests but that's another story :) )
|
||
// IPPROTO_MPTCP is defined in <netinet/in.h> on recent kernels only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it depends on the libc version in fact, not the kernel in fact but that's probably a detail)
s = socket(domain, SOCK_STREAM, IPPROTO_MPTCP); | ||
if(s==-1 && ( errno==EPROTONOSUPPORT || errno==ENOPROTOOPT) ) { | ||
// Multipath TCP is not supported on this system | ||
use_mptcp = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe good to re-add a clear error message?
fprintf(stderr, "Unable to create an MPTCP socket: "
"your kernel probably don't support MPTCP yet, "
"falling back to TCP for this socket and all the next ones.\n");
} | ||
} | ||
// Multipath TCP is not supported on this system, return a TCP socket | ||
return(socket(domain, SOCK_STREAM, IPPROTO_TCP)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(parenthesis not needed after the return
)
exit(0); | ||
} | ||
|
||
s = socket_create(AF_INET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe good to check for errors?
if (s < 0) {
fprintf(stderr, "Unable to create a socket\n");
exit(EXIT_FAILURE);
}
// do something useful with the socket
close(s);
return EXIT_SUCCESS;
// do something useful with the socket | ||
|
||
close(s); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(no need to have a return
to avoid a warning? Or maybe only visible with -Wall
?)
Code and README show how to detect that Multipath TCP is not enabled and fall back to regular TCP when Multipath TCP is not supported on the host.