34
34
* Private Functions
35
35
****************************************************************************/
36
36
37
+ #ifdef CONFIG_SYSLOG_BUFFER
37
38
/****************************************************************************
38
39
* Name: syslogstream_flush
39
40
****************************************************************************/
40
41
41
- #ifdef CONFIG_SYSLOG_BUFFER
42
- static int syslogstream_flush (FAR struct lib_syslogstream_s * stream )
42
+ static int syslogstream_flush (FAR struct lib_outstream_s * ostream )
43
43
{
44
- FAR struct iob_s * iob ;
44
+ FAR struct lib_syslogstream_s * stream = ( FAR void * ) ostream ;
45
45
int ret = OK ;
46
46
47
47
DEBUGASSERT (stream != NULL );
48
- iob = stream -> iob ;
49
48
50
49
/* Do we have an IO buffer? Is there anything buffered? */
51
50
52
- if (iob != NULL && iob -> io_len > 0 )
51
+ if (stream -> base != NULL && stream -> offset > 0 )
53
52
{
54
53
/* Yes write the buffered data */
55
54
56
55
do
57
56
{
58
- ssize_t nbytes = syslog_write ((FAR const char * )iob -> io_data ,
59
- iob -> io_len );
57
+ ssize_t nbytes = syslog_write (stream -> base , stream -> offset );
60
58
if (nbytes < 0 )
61
59
{
62
60
ret = nbytes ;
63
61
}
64
62
else
65
63
{
66
- iob -> io_len = 0 ;
67
64
ret = OK ;
68
65
}
69
66
}
70
67
while (ret == - EINTR );
71
68
}
72
69
70
+ stream -> offset = 0 ;
73
71
return ret ;
74
72
}
75
73
#endif
@@ -82,48 +80,49 @@ static int syslogstream_flush(FAR struct lib_syslogstream_s *stream)
82
80
static void syslogstream_addchar (FAR struct lib_syslogstream_s * stream ,
83
81
int ch )
84
82
{
85
- FAR struct iob_s * iob = stream -> iob ;
86
-
87
83
/* Add the incoming character to the buffer */
88
84
89
- iob -> io_data [ iob -> io_len ] = ch ;
90
- iob -> io_len ++ ;
85
+ stream -> base [ stream -> offset ] = ch ;
86
+ stream -> offset ++ ;
91
87
92
88
/* Increment the total number of bytes buffered. */
93
89
94
90
stream -> public .nput ++ ;
95
91
96
92
/* Is the buffer full? */
97
93
98
- if (iob -> io_len >= CONFIG_IOB_BUFSIZE )
94
+ if (stream -> offset >= stream -> size )
99
95
{
100
96
/* Yes.. then flush the buffer */
101
97
102
- syslogstream_flush (stream );
98
+ syslogstream_flush (& stream -> public );
103
99
}
104
100
}
105
101
102
+ /****************************************************************************
103
+ * Name: syslogstream_addstring
104
+ ****************************************************************************/
105
+
106
106
static int syslogstream_addstring (FAR struct lib_syslogstream_s * stream ,
107
107
FAR const char * buff , int len )
108
108
{
109
- FAR struct iob_s * iob = stream -> iob ;
110
109
int ret = 0 ;
111
110
112
111
do
113
112
{
114
- int remain = CONFIG_IOB_BUFSIZE - iob -> io_len ;
113
+ int remain = stream -> size - stream -> offset ;
115
114
remain = remain > len - ret ? len - ret : remain ;
116
- memcpy (iob -> io_data + iob -> io_len , buff + ret , remain );
117
- iob -> io_len += remain ;
115
+ memcpy (stream -> base + stream -> offset , buff + ret , remain );
116
+ stream -> offset += remain ;
118
117
ret += remain ;
119
118
120
119
/* Is the buffer enough? */
121
120
122
- if (iob -> io_len >= CONFIG_IOB_BUFSIZE )
121
+ if (stream -> offset >= stream -> size )
123
122
{
124
123
/* Yes.. then flush the buffer */
125
124
126
- syslogstream_flush (stream );
125
+ syslogstream_flush (& stream -> public );
127
126
}
128
127
}
129
128
while (ret < len );
@@ -151,17 +150,17 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
151
150
152
151
if (ch != '\r' )
153
152
{
154
- #ifdef CONFIG_SYSLOG_BUFFER
153
+ # ifdef CONFIG_SYSLOG_BUFFER
155
154
/* Do we have an IO buffer? */
156
155
157
- if (stream -> iob != NULL )
156
+ if (stream -> base != NULL )
158
157
{
159
158
/* Add the incoming character to the buffer */
160
159
161
160
syslogstream_addchar (stream , ch );
162
161
}
163
162
else
164
- #endif
163
+ # endif
165
164
{
166
165
int ret ;
167
166
@@ -208,9 +207,10 @@ static int syslogstream_puts(FAR struct lib_outstream_s *this,
208
207
stream -> last_ch = ((FAR const char * )buff )[len - 1 ];
209
208
210
209
#ifdef CONFIG_SYSLOG_BUFFER
210
+
211
211
/* Do we have an IO buffer? */
212
212
213
- if (stream -> iob != NULL )
213
+ if (stream -> base != NULL )
214
214
{
215
215
/* Add the incoming string to the buffer */
216
216
@@ -275,14 +275,28 @@ void lib_syslogstream_open(FAR struct lib_syslogstream_s *stream)
275
275
276
276
stream -> public .putc = syslogstream_putc ;
277
277
stream -> public .puts = syslogstream_puts ;
278
- stream -> public .flush = lib_noflush ;
279
278
stream -> public .nput = 0 ;
280
279
281
280
#ifdef CONFIG_SYSLOG_BUFFER
281
+ stream -> public .flush = syslogstream_flush ;
282
+
282
283
/* Allocate an IOB */
283
284
285
+ # ifdef CONFIG_MM_IOB
284
286
stream -> iob = iob_tryalloc (true);
287
+ if (stream -> iob != NULL )
288
+ {
289
+ stream -> base = (FAR void * )stream -> iob -> io_data ;
290
+ stream -> size = sizeof (stream -> iob -> io_data );
291
+ }
292
+ # else
293
+ stream -> base = stream -> buffer ;
294
+ stream -> size = sizeof (stream -> buffer );
295
+ # endif
296
+ #else
297
+ stream -> public .flush = lib_noflush ;
285
298
#endif
299
+ stream -> offset = 0 ;
286
300
}
287
301
288
302
/****************************************************************************
@@ -307,16 +321,20 @@ void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream)
307
321
308
322
/* Verify that there is an IOB attached (there should be) */
309
323
324
+ # ifdef CONFIG_MM_IOB
310
325
if (stream -> iob != NULL )
311
326
{
312
327
/* Flush the output buffered in the IOB */
313
328
314
- syslogstream_flush (stream );
329
+ syslogstream_flush (& stream -> public );
315
330
316
331
/* Free the IOB */
317
332
318
333
iob_free (stream -> iob );
319
334
stream -> iob = NULL ;
320
335
}
336
+ # else
337
+ syslogstream_flush (& stream -> public );
338
+ # endif
321
339
}
322
340
#endif
0 commit comments