1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the PKIX-C library.
16 * The Initial Developer of the Original Code is
17 * Sun Microsystems, Inc.
18 * Portions created by the Initial Developer are
19 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
22 * Sun Microsystems, Inc.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * Socket Object Type Definition
44 #ifndef _PKIX_PL_SOCKET_H
45 #define _PKIX_PL_SOCKET_H
48 #include "pkix_pl_common.h"
59 SOCKET_CONNECTPENDING
,
63 SOCKET_SENDRCVPENDING
,
67 /* This is the default port number, if none is supplied to CreateByName. */
71 * These callbacks allow a user to substitute a counterfeit socket in places
72 * where a PKIX_PL_Socket is expected. A conforming usage will use the
73 * ListenCallback function instead of Listen, AcceptCallback instead of Accept,
74 * etc. The counterfeit socket may have special capabilites such as the
75 * ability to do proxy authentication, etc.
79 (*pkix_pl_Socket_ListenCallback
)(
80 PKIX_PL_Socket
*socket
,
85 (*pkix_pl_Socket_AcceptCallback
)(
86 PKIX_PL_Socket
*socket
,
87 PKIX_PL_Socket
**pRendezvousSock
,
91 (*pkix_pl_Socket_ConnectContinueCallback
)(
92 PKIX_PL_Socket
*socket
,
97 (*pkix_pl_Socket_SendCallback
)(
98 PKIX_PL_Socket
*sendSock
,
100 PKIX_UInt32 bytesToWrite
,
101 PKIX_Int32
*pBytesWritten
,
105 (*pkix_pl_Socket_RecvCallback
)(
106 PKIX_PL_Socket
*rcvSock
,
108 PKIX_UInt32 capacity
,
109 PKIX_Int32
*pBytesRead
,
113 (*pkix_pl_Socket_PollCallback
)(
114 PKIX_PL_Socket
*sock
,
115 PKIX_Int32
*pBytesWritten
,
116 PKIX_Int32
*pBytesRead
,
120 (*pkix_pl_Socket_ShutdownCallback
)(
121 PKIX_PL_Socket
*socket
, void *plContext
);
123 typedef struct PKIX_PL_Socket_CallbackStruct
{
124 pkix_pl_Socket_ListenCallback listenCallback
;
125 pkix_pl_Socket_AcceptCallback acceptCallback
;
126 pkix_pl_Socket_ConnectContinueCallback connectcontinueCallback
;
127 pkix_pl_Socket_SendCallback sendCallback
;
128 pkix_pl_Socket_RecvCallback recvCallback
;
129 pkix_pl_Socket_PollCallback pollCallback
;
130 pkix_pl_Socket_ShutdownCallback shutdownCallback
;
131 } PKIX_PL_Socket_Callback
;
133 struct PKIX_PL_SocketStruct
{
134 PKIX_Boolean isServer
;
135 PRIntervalTime timeout
; /* zero for non-blocking I/O */
137 PRFileDesc
*clientSock
;
138 PRFileDesc
*serverSock
;
141 PKIX_UInt32 readBufSize
;
142 PKIX_UInt32 writeBufSize
;
144 PKIX_PL_Socket_Callback callbackList
;
147 /* see source file for function documentation */
149 PKIX_Error
*pkix_pl_Socket_RegisterSelf(void *plContext
);
152 pkix_pl_Socket_Create(
153 PKIX_Boolean isServer
,
154 PRIntervalTime timeout
, /* zero for non-blocking I/O */
157 PKIX_PL_Socket
**pSocket
,
161 pkix_pl_Socket_CreateByName(
162 PKIX_Boolean isServer
,
163 PRIntervalTime timeout
,
165 PRErrorCode
*pStatus
,
166 PKIX_PL_Socket
**pSocket
,
170 pkix_pl_Socket_CreateByHostAndPort(
171 PKIX_Boolean isServer
,
172 PRIntervalTime timeout
,
175 PRErrorCode
*pStatus
,
176 PKIX_PL_Socket
**pSocket
,
179 /* Do not use these functions directly; use their callback variants instead
180 * static PKIX_Error *
181 * pkix_pl_Socket_Listen(
182 * PKIX_PL_Socket *socket,
183 * PKIX_UInt32 backlog,
186 * static PKIX_Error *
187 * pkix_pl_Socket_Accept(
188 * PKIX_PL_Socket *socket,
189 * PKIX_PL_Socket **pRendezvousSock,
192 * static PKIX_Error *
193 * pkix_pl_Socket_ConnectContinue(
194 * PKIX_PL_Socket *socket,
195 * PRErrorCode *pStatus,
198 * static PKIX_Error *
199 * pkix_pl_Socket_Send(
200 * PKIX_PL_Socket *sendSock,
202 * PKIX_UInt32 bytesToWrite,
203 * PKIX_Int32 *pBytesWritten,
206 * static PKIX_Error *
207 * pkix_pl_Socket_Recv(
208 * PKIX_PL_Socket *rcvSock,
210 * PKIX_UInt32 capacity,
211 * PKIX_Int32 *pBytesRead,
214 * static PKIX_Error *
215 * pkix_pl_Socket_Poll(
216 * PKIX_PL_Socket *sock,
217 * PKIX_Int32 *pBytesWritten,
218 * PKIX_Int32 *pBytesRead,
221 * static PKIX_Error *
222 * pkix_pl_Socket_Shutdown(
223 * PKIX_PL_Socket *socket, void *plContext);
227 pkix_pl_Socket_GetCallbackList(
228 PKIX_PL_Socket
*socket
,
229 PKIX_PL_Socket_Callback
**pCallbackList
,
233 pkix_pl_Socket_GetPRFileDesc(
234 PKIX_PL_Socket
*socket
,
242 #endif /* _PKIX_PL_SOCKET_H */