From: Vlad Yasevich <vladislav.yasevich@hp.com>
To: linux-sctp@vger.kernel.org
Subject: Re: [PATCH 2/3] lksctp-tools: Add -T option to sctp_test
Date: Fri, 09 Jan 2009 14:36:16 +0000 [thread overview]
Message-ID: <496760E0.9050206@hp.com> (raw)
In-Reply-To: <4966E7AE.5070901@cn.fujitsu.com>
Hi Wei
Just 2 questions...
Wei Yongjun wrote:
> Add -T option to allow sctp_test use SOCK_STREAM tcp-style sockets.
>
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> ---
> src/apps/sctp_test.c | 61
> +++++++++++++++++++++++++++++++++++++++++++++-----
> 1 files changed, 55 insertions(+), 6 deletions(-)
>
> diff --git a/src/apps/sctp_test.c b/src/apps/sctp_test.c
> index 905a83e..fc93398 100644
> --- a/src/apps/sctp_test.c
> +++ b/src/apps/sctp_test.c
> @@ -157,6 +157,7 @@ int max_stream = 0;
> int seed = 0;
> int max_msgsize = DEFAULT_MAX_WINDOW;
> int assoc_pattern = ASSOC_PATTERN_SEQUENTIAL;
> +int socket_type = SOCK_SEQPACKET;
> int repeat_count = 0;
> int listeners = 0;
> int tosend = 0;
> @@ -243,6 +244,7 @@ void usage(char *argv0)
> fprintf(stderr, "\t-L num-ports (default value 0). Run the mixed
> mode\n");
> fprintf(stderr, "\t-S num-ports (default value 0). Run the mixed
> mode\n");
> fprintf(stderr, "\t-D drain. If in client mode do a read following
> send.\n");
> + fprintf(stderr, "\t-T use SOCK_STREAM tcp-style sockets.\n");
> fprintf(stderr, "\n");
> fflush(stderr);
>
> @@ -469,9 +471,10 @@ int socket_r(void)
> struct sctp_event_subscribe subscribe;
> int sk, error;
>
> - DEBUG_PRINT(DEBUG_MIN, "\tsocket(SOCK_SEQPACKET, IPPROTO_SCTP)");
> + DEBUG_PRINT(DEBUG_MIN, "\tsocket(%s, IPPROTO_SCTP)",
> + (socket_type = SOCK_SEQPACKET) ? "SOCK_SEQPACKET" :
> "SOCK_STREAM");
>
> - if ((sk = socket(s_loc.ss_family, SOCK_SEQPACKET, IPPROTO_SCTP)) <
> 0 ) {
> + if ((sk = socket(s_loc.ss_family, socket_type, IPPROTO_SCTP)) < 0 ) {
> if (do_exit) {
> fprintf(stderr, "\n\n\t\t*** socket: failed to create"
> " socket: %s ***\n",
> @@ -573,6 +576,41 @@ int listen_r(int sk, int listen_count)
>
> } /* listen_r() */
>
> +int accept_r(int sk){
> + socklen_t len = 0;
> + int subsk;
> +
> + DEBUG_PRINT(DEBUG_MIN, "\taccept(sk=%d)\n", sk);
> +
> + subsk = accept(sk, NULL, &len);
> + if (subsk < 0) {
> + fprintf(stderr, "\n\n\t\t*** accept: %s ***\n\n\n",
> strerror(errno));
> + exit(1);
> + }
> +
> + return subsk;
> +} /* accept_r() */
> +
> +int connect_r(int sk, const struct sockaddr *serv_addr, socklen_t addrlen)
> +{
> + int error = 0;
> +
> + DEBUG_PRINT(DEBUG_MIN, "\tconnect(sk=%d)\n", sk);
> +
> + /* Mark sk as being able to accept new associations */
> + error = connect(sk, serv_addr, addrlen);
> + if (error != 0) {
> + if (do_exit) {
> + fprintf(stderr, "\n\n\t\t*** connect: %s ***\n\n\n",
> + strerror(errno));
> + exit(1);
> + }
> + else return -1;
> + }
> + return 0;
> +
> +} /* connect_r() */
> +
> int receive_r(int sk, int once)
> {
> int i = 0, error = 0;
> @@ -832,7 +870,7 @@ server(int sk)
> }
> }
>
> - receive_r(sk, 0);
> + receive_r(sk, (socket_type = SOCK_STREAM) ? 1 : 0);
>
Why only 1 message in the TCP case? The client can send multiple messages.
> } /* server() */
>
> @@ -1095,7 +1133,7 @@ clean_up:
>
> void start_test(int role)
> {
> - int sk;
> + int sk, subsk = -1;
> int i = 0;
>
> DEBUG_PRINT(DEBUG_NONE, "\nStarting tests...\n");
> @@ -1114,6 +1152,12 @@ void start_test(int role)
>
> if (role = SERVER) {
> listen_r(sk, 100);
> + if (socket_type = SOCK_STREAM)
> + subsk = accept_r(sk);
> + else
> + subsk = sk;
> + } else if (socket_type = SOCK_STREAM) {
> + connect_r(sk, (struct sockaddr *)&s_rem, r_len);
> }
>
Looks like in the TCP case, this code will only accept 1 connection and then
end. So multiple connections will fail to work. Is that on purpose? Should
this be update to allow for multiple connections?
Thanks
-vlad
> if (!debug_level) {
> @@ -1125,7 +1169,7 @@ void start_test(int role)
> if (role = SERVER) {
> DEBUG_PRINT(DEBUG_NONE,
> "Server: Receiving packets.\n");
> - server(sk);
> + server(subsk);
> } else {
> DEBUG_PRINT(DEBUG_NONE,
> "Client: Sending packets.(%d/%d)\n",
> @@ -1136,6 +1180,8 @@ void start_test(int role)
> fflush(stdout);
> }
>
> + if (role = SERVER && socket_type = SOCK_STREAM)
> + close_r(subsk);
> close_r(sk);
>
> } /* start_test() */
> @@ -1149,7 +1195,7 @@ main(int argc, char *argv[])
> struct sockaddr_in6 *t_addr6;
>
> /* Parse the arguments. */
> - while ((c = getopt(argc, argv,
> ":H:L:P:S:a:h:p:c:d:lm:sx:X:o:t:M:r:w:Di:")) >= 0 ) {
> + while ((c = getopt(argc, argv,
> ":H:L:P:S:a:h:p:c:d:lm:sx:X:o:t:M:r:w:Di:T")) >= 0 ) {
>
> switch (c) {
> case 'H':
> @@ -1281,6 +1327,9 @@ main(int argc, char *argv[])
> case 'i':
> interface = optarg;
> break;
> + case 'T':
> + socket_type = SOCK_STREAM;
> + break;
> case '?':
> default:
> usage(argv[0]);
next prev parent reply other threads:[~2009-01-09 14:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-09 5:59 [PATCH 2/3] lksctp-tools: Add -T option to sctp_test Wei Yongjun
2009-01-09 14:36 ` Vlad Yasevich [this message]
2009-01-12 9:18 ` Wei Yongjun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=496760E0.9050206@hp.com \
--to=vladislav.yasevich@hp.com \
--cc=linux-sctp@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.