Author Topic: Idea: Socket class  (Read 2209 times)

Offline whitelynx

  • GNE Founder
  • Head Code Monkey
  • Commodore
  • *****
  • Posts: 304
  • Karma: +4/-0
  • Internet Idiocy Pundit
    • View Profile
Idea: Socket class
« on: October 05, 2006, 06:18:34 pm »
Right now we're making a thin class to wrap socket functionality, called Socket. I have some ideas for making it a bit more than a strict thin wrapper that I think might make it easier to use.

  • Socket subclasses - create two smaller subclasses of Socket, ListenSocket and ConnectSocket, to handle the functionality for incoming and outgoing sockets, respectively. (if you're wondering about the names, take a look at any classic BSD sockets implementation) This makes all of the individual Socket files a bit easier to read through, as the read/write functionality is common to all sockets, but a listening socket can't connect, and a connecting socket can't listen.
  • Move some functionality to the constructor - open() should only need to be called once during the lifetime of a socket, and it must be called before anything else can be done, so I think it makes sense to put that into the constructor. Similarly, either listen() or connect() must be called on a socket before anything except open(), so it would make sense to put those in the constructors of their respective socket types. (or, if we don't split Socket into subclasses, simply have convenience constructors that take care of the listen/connect functionality.)
  • Move statistics functionality out of Socket - Statistics are nice, but I don't think their functionality logically belongs inside Socket... it may make more sense to move it to its own Statistics class that all Sockets register with, and they don't record statistics unless there is an attached Statistics object. (see my comments on the wiki for more thoughts)
"Without music, life is a mistake, a trial, an exile."
 - Nietzsche

Offline Morgul

  • GNE Founder
  • Godlike Fuzzy Dice
  • Grand Admiral
  • **********
  • Posts: 2086
  • Karma: +21/-4
  • Godlike Fuzzy Dice
    • View Profile
    • G33X Nexus Entertainment
Re: Idea: Socket class
« Reply #1 on: October 05, 2006, 06:47:55 pm »
As someone who knows 2% about sockets, I think this makes a good deal of sense. Even though I'm not in charge of this, I support the change. It would make a good deal more sense to deal with, imho.

I also really like the idea of moving statistics out of sockets. They don't belong there.
"Just because my math may tell lies doesn't mean that I don't understand the quantum mechanics of it all." --Caenus

The popular videogame "Doom" is based loosely around the time Satan borrowed two bucks from Vin Diesel and forgot to pay him back.

"In the beginning there was nothing. And it exploded." --Terry Pratchett

Offline Rosencrantz

  • Gray Haired
  • Lieutenant Commander
  • ****
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Idea: Socket class
« Reply #2 on: October 06, 2006, 06:22:57 am »
Sounds good to me. Toss bind and listen into the constructor for ListenSocket, and connect into the constructor for ConnectSocket. I don't really know anything about the statistics, but your idea sounds good to me.


Offline contingencyplan

  • Villain
  • Moderator
  • Admiral
  • *****
  • Posts: 977
  • Karma: +1/-0
  • Must I sin once, and repent forever?
    • View Profile
    • My Blog
Re: Idea: Socket class
« Reply #3 on: October 09, 2006, 04:53:23 am »
Well, I said I would have some comments for you when you woke up. Then I got involved in this Cooke paper, and all of a sudden it's almost 6am and I have a test in 5 hours. So my comments are gonna be brief for now.

  • Socket subclasses - create two smaller subclasses of Socket, ListenSocket and ConnectSocket, to handle the functionality for incoming and outgoing sockets, respectively. (if you're wondering about the names, take a look at any classic BSD sockets implementation) This makes all of the individual Socket files a bit easier to read through, as the read/write functionality is common to all sockets, but a listening socket can't connect, and a connecting socket can't listen.

Generally, I like the idea. We can move forward on this for now, and see where it takes us, reserving the right to backtrack sometime down the line.

Quote
  • Move some functionality to the constructor - open() should only need to be called once during the lifetime of a socket, and it must be called before anything else can be done, so I think it makes sense to put that into the constructor. Similarly, either listen() or connect() must be called on a socket before anything except open(), so it would make sense to put those in the constructors of their respective socket types. (or, if we don't split Socket into subclasses, simply have convenience constructors that take care of the listen/connect functionality.)

Again, generally like the idea. Again, we'll start moving on this path, and see what happens. I'll definitely know more when I start back in on the code later this week (after things have died down a bit school-wise).

Quote
  • Move statistics functionality out of Socket - Statistics are nice, but I don't think their functionality logically belongs inside Socket... it may make more sense to move it to its own Statistics class that all Sockets register with, and they don't record statistics unless there is an attached Statistics object. (see my comments on the wiki for more thoughts)

Personally, I'd just as soon keep the stats within the Socket class. I don't see a reason for moving them to another class that the Socket then has to register itself with. As far as the performance gain (no stats are recorded unless the Socket is registered with the a Stats object), we can implement that a bit more simply as a flag (and perhaps using some magic make it perform just as well; dunno yet). To me, though, the stats are something that the Socket knows about itself, so it makes sense to have it within the Socket class. This is something I'd like to hear a more detailed argument for.

At any rate, I'm gonna call it a night. Cy'all tomorrow!
We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. 
    ~Robert Wilensky

It is not bigotry to be certain we are right; but it is bigotry to be unable to imagine how we might possibly have gone wrong.
    ~GK Chesterton

Men never do evil so completely and cheerfully as when they do it from a religious conviction.
    ~Blaise Pascal

Offline whitelynx

  • GNE Founder
  • Head Code Monkey
  • Commodore
  • *****
  • Posts: 304
  • Karma: +4/-0
  • Internet Idiocy Pundit
    • View Profile
Re: Idea: Socket class
« Reply #4 on: October 10, 2006, 02:08:23 pm »
For now, I'm not too worried about the statistics stuff... I think it clutters up the interface, but I can see why it's in Socket. Other than that, since there seems to be no argument about the other two points, I'm going to start implementing them.
"Without music, life is a mistake, a trial, an exile."
 - Nietzsche