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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
#ifndef DK4SOCKA_H_INCLUDED
#define DK4SOCKA_H_INCLUDED 1
/** @file dk4socka.h Socket functions with application support.
*/
#ifndef DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif
#ifndef DK4TYPES_H_INCLUDED
#include "dk4types.h"
#endif
#ifndef DK4CONST_H_INCLUDED
#include "dk4const.h"
#endif
#ifndef DK4SOCK_H_INCLUDED
#include "dk4sock.h"
#endif
#ifndef DK4APP_H_INCLUDED
#include "dk4app.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
Logging functions.
------------------
Module: dk4socka01
*/
/** Retrieve number of log texts in localized string array.
@return Number of elements.
*/
size_t
dk4socket_log_num_texts(void);
/** Retrieve function name and error code text.
On success the function sets the output variables to valid
pointers, on error they are set to NULL.
@param fctname Address of pointer variable for function name.
@param msgtext Address of pointer variable for error code text.
@param app Application structure.
@param erp Error report.
*/
void
dk4socket_log_fctname_msg(
const dkChar **fctname,
const dkChar **msgtext,
dk4_app_t *app,
dk4_er_t *erp
);
/** Retrieve array containing localized strings.
@param app Application structure, required here.
@return Pointer to localized strings array.
*/
const dkChar * const *
dk4socket_log_texts(dk4_app_t *app);
/** Issue simple log message, one component.
@param app Application structure.
@param ll Log level.
@param imain Index of main text in array of localized texts.
@param erp Error report containing details, may be NULL.
*/
void
dk4socket_log_simple_1(
dk4_app_t *app,
int ll,
size_t imain,
dk4_er_t *erp
);
/** Issue simple log message, one component.
@param app Application structure.
@param ll Log level.
@param i1 Index of main text in array of localized texts.
@param i2 Index of second text in array of localized texts.
@param ctext Customized text piece.
@param erp Error report containing details, may be NULL.
*/
void
dk4socket_log_simple_3(
dk4_app_t *app,
int ll,
size_t i1,
size_t i2,
const dkChar *ctext,
dk4_er_t *erp
);
/** Issue simple log message, five components.
@param app Application structure.
@param ll Log level.
@param i1 Index of main text in array of localized texts.
@param i2 Index of third text in array of localized texts.
@param i3 Index of fifth text in array of localized texts.
@param ct1 Customized text piece 1.
@param ct2 Customized text piece 2.
@param erp Error report containing details, may be NULL.
*/
void
dk4socket_log_simple_5(
dk4_app_t *app,
int ll,
size_t i1,
size_t i2,
size_t i3,
const dkChar *ct1,
const dkChar *ct2,
dk4_er_t *erp
);
/*
Bring socket subsystem up and down.
-----------------------------------
Module: dk4socka02
*/
/** Bring socket subsystem up.
@param app Application structure for diagnostics.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
Error codes:
* DK4_E_SOCKET_UP<br>
with WSAGetLastError() result in iDetails1 if a WinSock
error occured.
*/
int
dk4socket_up_app(dk4_app_t *app);
/** Bring socket subsystem down.
@param app Application structure for diagnostics.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
Error codes:
* DK4_E_SOCKET_DOWN<br>
with WSAGetLastError() result in iDetails1 if a WinSock
error occured.
*/
int
dk4socket_down_app(dk4_app_t *app);
/*
Open and close sockets.
-----------------------
Module: dk4socka03
*/
/** Open a socket.
@param af Address family (AF_INET or AF_INET6).
@param tp Socket type (SOCK_STREAM or SOCK_DGRAM).
@param pr Protocol number.
@param app Application structure for diagnostics, may be NULL.
@return Valid socket on success, INVALID_SOCKET on error.
*/
dk4_socket_t
dk4socket_open_app(int af, int tp, int pr, dk4_app_t *app);
/** Shut down a socket.
@param so Socket to shutdown.
@param how How to shut down the socket, one from:
DK4_SOCKET_SHUT_READ, DK4_SOCKET_SHUT_WRITE, or
DK4_SOCKET_SHUT_RDWR.
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_shutdown_app(dk4_socket_t so, int how, dk4_app_t *app);
/** Close a socket.
@param so Socket to close.
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_close_app(dk4_socket_t so, dk4_app_t *app);
/*
Bind local address.
-------------------
Module: dk4socka04
*/
/** Bind local address.
@param sock Socket to configure.
@param pAddr Pointer to address variable.
@param szAddr Size of address.
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_bind_app(
dk4_socket_t sock,
const struct sockaddr *pAddr,
size_t szAddr,
dk4_app_t *app
);
/*
Listen and accept incoming connection requests.
-----------------------------------------------
Module: dk4socka05
*/
/** Listen for incoming connection requests.
@param sock Server side socket already bound to local address.
@param bl Backlog (number of connection requests to keep
in the queue).
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_listen_app(
dk4_socket_t sock,
int bl,
dk4_app_t *app
);
/** Accept an incoming connection.
@param sock Server socket in listening state.
@param pAddr Buffer for remote address.
@param pSzAddr Pointer to address buffer size variable,
in: buffer size, out: used buffer size.
@param app Application structure for diagnostics, may be NULL.
@return Valid socket on success, INVALID_SOCKET on error.
*/
dk4_socket_t
dk4socket_accept_app(
dk4_socket_t sock,
struct sockaddr *pAddr,
size_t *pSzAddr,
dk4_app_t *app
);
/*
Create a tcp client socket.
---------------------------
Module: dk4socka07
*/
/** Create TCP connection to specified remote host and service.
@param hostname Remote host name to connect to.
@param svcname Remote service name to connect to.
@param lsvcname Local service name, may be NULL.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param app Application structure for diagnostics,
may be NULL.
@return Valid socket on success, INVALID_SOCKET on error.
*/
dk4_socket_t
dk4socket_tcp_client_for_host_service_app(
const dkChar *hostname,
const dkChar *svcname,
const dkChar *lsvcname,
long secs,
long usecs,
dk4_app_t *app
);
/** Create TCP connection to specified remote host and service.
@param hostname Remote host name to connect to.
@param svcname Remote service name to connect to.
@param lsvcname Local service name, may be NULL.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param nsrv Flag: Service names contain numbers only.
@param app Application structure for diagnostics,
may be NULL.
@return Valid socket on success, INVALID_SOCKET on error.
*/
dk4_socket_t
dk4socket_tcp_client_for_host_num_service_app(
const dkChar *hostname,
const dkChar *svcname,
const dkChar *lsvcname,
long secs,
long usecs,
int nsrv,
dk4_app_t *app
);
/** Create TCP connection to specified remote host and port.
@param hostname Remote host name to connect to.
@param portno Remote port to connect to.
@param lportno Local port number, 0 for arbitrary port.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param app Application structure for diagnostics,
may be NULL.
@return Valid socket on success, INVALID_SOCKET on error.
*/
dk4_socket_t
dk4socket_tcp_client_for_host_port_app(
const dkChar *hostname,
unsigned short portno,
unsigned short lportno,
long secs,
long usecs,
dk4_app_t *app
);
/*
Send and receive data.
----------------------
Module: dk4socka08
*/
/** Attempt to send data.
@param sock Socket to use.
@param buf Address of buffer containing data.
@param pszbuf Pointer to size variable (in: buffer size, out:
bytes transferred).
@param flags Flags.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param app Application structure for diagnostics, may be NULL.
@param complain Flag: Complain on partial send.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_IN_PROGRESS on partial success (not all bytes
transferred),
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_send_attempt_app(
dk4_socket_t sock,
const void *buf,
size_t *pszbuf,
int flags,
long secs,
long usecs,
dk4_app_t *app,
int complain
);
/** Send data.
@param sock Socket to use.
@param buf Address of buffer containing data.
@param pszbuf Pointer to size variable (in: buffer size, out:
bytes transferred).
@param flags Flags.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_IN_PROGRESS on partial success (not all bytes
transferred),
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_send_app(
dk4_socket_t sock,
const void *buf,
size_t *pszbuf,
int flags,
long secs,
long usecs,
dk4_app_t *app
);
/** Receive data.
@param sock Socket to use.
@param buf Address of buffer for data.
@param pszbuf Pointer to size variable (in: buffer size, out:
bytes received).
@param flags Flags.
@param secs Seconds for timeout.
@param usecs Microseconds for timeout.
@param app Application structure for diagnostics, may be NULL.
@return DK4_SOCKET_RESULT_SUCCESS on success,
DK4_SOCKET_RESULT_FAILED on error.
*/
int
dk4socket_recv_app(
dk4_socket_t sock,
void *buf,
size_t *pszbuf,
int flags,
long secs,
long usecs,
dk4_app_t *app
);
/** Create listener socket set.
@param servicename Service name or number.
@param backlog Number of queued requests.
@param local Flag: Listen on localhost interface only.
@param app Application structure for diagnostics, may be NULL.
@return Pointer to socket set on success, NULL on error.
*/
dk4_socket_set_t *
dk4socket_set_service_app(
const dkChar *servicename,
int backlog,
int local,
dk4_app_t *app
);
#ifdef __cplusplus
}
#endif
#endif
/* ifndef DK4SOCKA_H_INCLUDED */
|