File: CWConnection.h

package info (click to toggle)
pantomime 1.4.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,288 kB
  • sloc: objc: 22,039; makefile: 11; sh: 4
file content (125 lines) | stat: -rw-r--r-- 4,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
**  CWConnection.h
**
**  Copyright (c) 2001-2016 Ludovic Marcotte
**
**  Author: Ludovic Marcotte <ludovic@Sophos.ca>
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**  
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**  Lesser General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _Pantomime_H_CWConnection
#define _Pantomime_H_CWConnection

#include <sys/types.h>

#import <Foundation/NSData.h>
#import <Foundation/NSString.h>

/*!
  @protocol CWConnection
  @discussion This protocol defines a basic set of methods that classes
              should implement. CWTCPConnection implements the protocol
	      to offer TCP connections support. An UDP implementation
	      will likely be added in a near future (for DNS requests).
*/
@protocol CWConnection 

/*!
  @method initWithName: port: background:
  @discussion This method is use to initialize a new connection
              instance at the specified port. It can connect
	      in background if needed and use the default timeout
	      (60 seconds) when connecting.
  @param theName The host name to connect to.
  @param thePort The port to connect to.
  @param theBOOL YES if we want to connect in background (non-blocking
                 way), NO if we want this call to be blocking until
		 we successfully connected to the host.
  @result An instance implementing the CWConnection protocol, nil
	  if an error occurred, like DNS resolution.
*/
- (id) initWithName: (NSString *) theName
               port: (unsigned int) thePort
         background: (BOOL) theBOOL;

/*!
  @method initWithName: port: connectionTimeout: readTimeout: writeTimeout: background:
  @discussion Same as -initWithName: port: background but it allows
              you to specifed the proper connection / read / write
	      timeout values to use.
  @param theName The host name to connect to.
  @param thePort The port to connect to.
  @param theConnectionTimeout The timeout to use when connecting to the host.
  @param theReadTimeout The timeout to use when reading on the socket.
  @param theWriteTimeout The timeout to use when writing on the socket.
  @param theBOOL YES if we want to connect in background (non-blocking
                 way), NO if we want this call to be blocking until
		 we successfully connected to the host.
  @result An instance implementing the CWConnection protocol, nil
	  if an error occurred, like DNS resolution.
*/
- (id) initWithName: (NSString *) theName
	       port: (unsigned int) thePort
  connectionTimeout: (unsigned int) theConnectionTimeout
	readTimeout: (unsigned int) theReadTimeout
       writeTimeout: (unsigned int) theWriteTimeout
         background: (BOOL) theBOOL;

/*!
  @method fd
  @discussion This method is used to obtain the file descriptor
              which is associated to our connection.
  @result The file descriptor, -1 if the socket isn't yet connected.
*/
- (int) fd;

/*!
  @method isConnected
  @discussion This method is used to verify if the socket is
              in a connected state.
  @result YES if the socket is in a connected state, NO otherwise.
*/
- (BOOL) isConnected;

/*!
  @method close
  @discussion This method is used to close the connection to the host.
*/
- (void) close;

/*!
  @method read: length:
  @discussion This method is used to read <i>len</i> bytes from the
              socket and store them in <i>buf</i>
  @param buf The buffer in which read bytes will be stored in.
  @param len The number of bytes we want to try to read.
  @result The number of bytes successfully read.
*/
- (ssize_t) read: (char *) buf
      length: (size_t) len;

/*!
  @method write: length:
  @discussion This method is used to write <i>len</i> bytes from
              <i>buf</i> to the socket.
  @param buf The bytes that we want to write to the socket.
  @param len The number of bytes we want to try to write.
  @result The number of bytes successfully written.
*/
- (ssize_t) write: (char *) buf
       length: (size_t) len;
@end

#endif // _Pantomime_H_CWConnection