Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-01-05 12:54:31


on 1/3/01 3:04 AM, Joseph Berrios at jsberrios_at_[hidden] wrote:

> Daryle,
>
> thanks for your response and thoughts. To be honest with you I have
> no idea how the streambuf works. I am currently looking for a
> tutorial on the iostreams and specially the streambuf. Is there any
> book or a gentle tutorial that explains the streambuf library and how
> can it be used to extend it for a new type?

I learned a lot from _The C++ Standard Library: A Tutorial and Reference_ by
Nicolai M. Josuttis. I think there's another book that is just about
IOStreams. Also, stream-god Dietmar Kuehl hangs around on this list.

But I'm not sure if streams can fit the general socket model you're making.
It could fit parts, like a particular, guaranteed connection, but not one
and only one stream per socket.

> answering your questions:
>
>> 1. What is binding? Is it required before accepting and/or connecting? Does
>> terminating a point affect binding? Can a re-bind or an un-bind be done?
>
> The bind command is used to let the application specify the local IP
> address and local port, for both TCP and UDP. By doing so this
> function assings a local protocol address to a socket. Usually this
> command is used with the server socket.
>
> If the socket terminating is a client, it will not affect the
> binding. If the server terminates, then the address and port will be
> free to be used by another program.
>
> I don't know if re-bind or an unbind can be done. I checked my
> references and couldn't find any answers.

Another poster, Gregory Seidman, gave an improved response. (Binds must be
done before connections, otherwise a default bind is done on the first
connection. Binds cannot generally be shifted or undone.) I was thinking
that maybe the socket class could have a constructor that lets the bind be
done at the end of construction.

>> 2. Can a socket simultaneously be a server (accept) and a client (connect)?
>> If so, can the two points be unrelated, or do they have to go to the same
>> remote location?
>
> as the socket class is designed now, it does not support to use one
> socket for both client and server. There is a command in the UNIX
> API called socketpair that allows the same socket to be used by both
> the client and the server.
[SNIP references and past replies]

As Seidman responded, simultaneous client/server socket use cannot be done
generally. This means that a socket object would have one of three
connection states: server, client, or disconnected. You don't have to have
separate methods for server disconnection and client disconnection, just
have a single 'disconnect' method that chooses the right low-level command
based on the connection state ('close' for client, 'shutdown' for server,
and nothing if already disconnected).

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk