From: Bill Cunningham on
I created a bond socket and included the addrlen struct and connect()
function. I used send and not sedmgr and recieved various numbers of values
as I changed the msg parameter. To me that means that the ourgoing TCP type
socket I created and was toying with worked.

Now I have a question about sendmsg(), poll() and select(). I believe I
can sendmsg() and send and receive data as a client but what about
nultiplexing? Should poll() or select() be used ? Too those who know.

Bill


From: Scott Lurndal on
"Bill Cunningham" <nospam(a)nspam.invalid> writes:

> Now I have a question about sendmsg(), poll() and select(). I believe I
>can sendmsg() and send and receive data as a client but what about
>nultiplexing? Should poll() or select() be used ? Too those who know.
>
>Bill

I prefer poll(2) over select(2), but my background is SYSV, not BSD. I think
poll is more flexible than select (and older select implementations had a
relatively small limit on the maximum file descriptor that could be used).

scott
From: Bill Cunningham on

"Scott Lurndal" <scott(a)slp53.sl.home> wrote in message
news:Derzn.3$XD2.1(a)news.usenetserver.com...

> I prefer poll(2) over select(2), but my background is SYSV, not BSD. I
> think
> poll is more flexible than select (and older select implementations had a
> relatively small limit on the maximum file descriptor that could be used).

Maybe you can help me with a client to the echo port. The way I
understand it from reading opengroup's posix standard a client doesn't need
the ai_flags member set. I usually set it to the macro AF_PASSIVE but it and
bind() must only be for servers. Here's what I have so far:

#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>

int sock, s, c, g;

struct addrinfo ad, *adp;

int main(int argc, char **argv)
{
memset(&ad, '\0', sizeof ad);
ad.ai_family = AF_INET;
ad.ai_socktype = SOCK_STREAM;
if ((g = getaddrinfo(argv[1], "7", &ad, &adp)) != 0) {
fprintf(stderr, "Error > %s\n", gai_strerror(g));
exit(1);
}
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket error");
exit(1);
}
if ((c = connect(sock, adp->ai_addr, adp->ai_addrlen)) == -1) {
perror("connect error");
exit(1);
}

Notice that getinfoaddr()'s first parameter isn't set to NULL as I have
read. Is this set just for servers? I want to send echo packets out and
receive them. I don't think I would need to write server code too would I?

Bill


From: Bill Cunningham on

"Bill Cunningham" <nospam(a)nspam.invalid> wrote in message
news:4bcede4a$0$12418$bbae4d71(a)news.suddenlink.net...

> Maybe you can help me with a client to the echo port. The way I
> understand it from reading opengroup's posix standard a client doesn't
> need the ai_flags member set. I usually set it to the macro AF_PASSIVE

Oops. that should be AI_PASSIVE.

Bill


From: Scott Lurndal on
"Bill Cunningham" <nospam(a)nspam.invalid> writes:
>
>"Scott Lurndal" <scott(a)slp53.sl.home> wrote in message
>news:Derzn.3$XD2.1(a)news.usenetserver.com...
>
>> I prefer poll(2) over select(2), but my background is SYSV, not BSD. I
>> think
>> poll is more flexible than select (and older select implementations had a
>> relatively small limit on the maximum file descriptor that could be used).
>
> Maybe you can help me with a client to the echo port. The way I
>understand it from reading opengroup's posix standard a client doesn't need
>the ai_flags member set. I usually set it to the macro AF_PASSIVE but it and
>bind() must only be for servers. Here's what I have so far:

Here's a more modern example:

/**
* [Re]Connect to the server.
*/
bool
c_netport::connect_to_server(void)
{
struct addrinfo hints;
struct addrinfo *res;
struct sockaddr_in *sin;
int diag;

memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;

n_logger->log("%s Connecting to %s:%hu\n", n_subsys, n_hostname, n_port);
diag = ::getaddrinfo(n_hostname, NULL, &hints, &res);
if (diag != 0) {
n_logger->log("%s Unable to get address for host '%s'\n\t%s\n",
n_subsys, n_hostname, gai_strerror(diag));
return false;
}

sin = (struct sockaddr_in *) res->ai_addr;
sin->sin_port = htons(n_port);

n_connect_socket = ::socket(res->ai_family,
res->ai_socktype, res->ai_protocol);
if (n_connect_socket == -1) {
n_logger->log("%s Unable to obtain socket: %s\n",
n_subsys, strerror(errno));
return false;
}

diag = ::fcntl(n_connect_socket, F_SETFD, FD_CLOEXEC);
if (diag == -1) {
n_logger->log("%s: Unable to set CLOEXEC on socket FD: %s\n",
n_subsys, strerror(errno));
}

retry:
diag = ::connect(n_connect_socket, res->ai_addr, res->ai_addrlen);
if (diag == -1) {
if ((errno == ECONNREFUSED)
|| (errno == ETIMEDOUT)) {
sleep(5);
if (n_terminate) {
freeaddrinfo(res);
return false;
}
goto retry;
}

freeaddrinfo(res);

n_logger->log("%s Unable to connect to %s:%hu: %s\n",
n_subsys, n_hostname, n_port, strerror(errno));
return false;
}

snprintf(n_connection_name, sizeof(n_connection_name), "%s:%hu",
n_hostname, n_port);

p_transport->connect_callback(this);

freeaddrinfo(res);

return true;
}
 |  Next  |  Last
Pages: 1 2
Prev: Does "df" modify the ext2 filesystem
Next: book