~ubuntu-branches/ubuntu/karmic/starvoyager/karmic

« back to all changes in this revision

Viewing changes to sockhelper.h

  • Committer: Bazaar Package Importer
  • Author(s): Idan Sofer
  • Date: 2003-08-01 16:55:13 UTC
  • Revision ID: james.westby@ubuntu.com-20030801165513-0ueb129iym99k7tg
Tags: upstream-0.4.4
ImportĀ upstreamĀ versionĀ 0.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        sockhelper.h
 
3
        
 
4
        (c) Richard Thrippleton
 
5
        Licensing terms are in the 'LICENSE' file
 
6
        If that file is not included with this source then permission is not given to use this source in any way whatsoever.
 
7
*/
 
8
#include <SDL_net.h>
 
9
 
 
10
class sockhelper //Class that helps with socket operations, giving them much easier non-blocking semantics
 
11
{
 
12
        public:
 
13
        sockhelper(TCPsocket sock); //Constructor, give it the socket to help with
 
14
        ~sockhelper(); //Destructor, cleans up any dynamic data
 
15
 
 
16
        void pump(); //Pump scheduled outgoing data, fill incoming buffer
 
17
        void send(unsigned char* data,int len); //Schedule data of given length to be sent
 
18
        unsigned char* request(int len); //Request incoming data of given length, returns null if not enough in the buffer
 
19
        void suck(); //Way to roll on the stream after a request has been used and totally done with
 
20
        long getcount(); //Get the socket throughput byte count, and reset it to zero
 
21
 
 
22
        private:
 
23
        static Uint32 alarmcallback(Uint32 dly,void* from); //Callback handling the alarm when pumping blocks for too long
 
24
        TCPsocket sock; //Socket to help with
 
25
        SDLNet_SocketSet poll; //For polling input
 
26
        unsigned char in[2048]; //Input buffer
 
27
        int ins; //Size of input buffer used
 
28
        unsigned char out[1024]; //Output buffer
 
29
        int outs; //Size of output buffer used
 
30
        int take; //Record how much was requested (for the suck operation)
 
31
        long cnt; //Count of bytes come through the socket
 
32
        SDL_TimerID alrm; //The blocking alarm being set
 
33
        bool blck; //Flag to indicate that the socket outgoing has blocked and should be deleted as soon as safe
 
34
};