taskrambler  0.1.9
Web server and task management solution.
stream/stream.h File Reference
#include <sys/types.h>
#include <openssl/ssl.h>
#include "class.h"
+ Include dependency graph for stream/stream.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  StreamHandleType { STREAM_FD = 0, STREAM_SSL }
 

Functions

 CLASS (Stream)
 
ssize_t streamRead (Stream, void *, size_t)
 
ssize_t streamWrite (Stream, void *, size_t)
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program 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 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/.

Definition in file stream/stream.h.

Enumeration Type Documentation

Enumerator
STREAM_FD 
STREAM_SSL 

Definition at line 31 of file stream/stream.h.

31  {
32  STREAM_FD = 0,
StreamHandleType
Definition: stream/stream.h:31

Function Documentation

CLASS ( Stream  )

Definition at line 36 of file stream/stream.h.

36  {
37  StreamHandleType type;
38  union {
39  int fd;
40  SSL * ssl;
41  } handle;
42 };
StreamHandleType
Definition: stream/stream.h:31
ssize_t streamRead ( Stream  ,
void *  ,
size_t   
)

Definition at line 35 of file stream/read.c.

References logger, LOGGER_DEBUG, loggerLog(), STREAM_FD, and STREAM_SSL.

Referenced by cbufRead().

36 {
37  ssize_t done;
38 
39  switch(this->type) {
40  ssize_t _read;
41 
42  case STREAM_FD:
43  _read = read((this->handle).fd, buf, count);
44 
45  if (_read < 0) {
46  switch (errno) {
47  case EINTR:
48  case ENOMEM:
49  done = 0;
50  break;
51  case (EAGAIN|EWOULDBLOCK):
52  done = -1;
53  break;
54  default:
55  done = -2;
56  break;
57  }
58  } else if (_read == 0) {
59  done = -2;
60  } else {
61  done = _read;
62  }
63 
64  break;
65 
66  case STREAM_SSL:
67  done = SSL_read((this->handle).ssl, buf, count);
68 
69  if (0 == done) {
70  done = -2;
71  } else if (0 > done) {
72  switch (SSL_get_error((this->handle).ssl, done)) {
73  case SSL_ERROR_SYSCALL:
74  {
75  switch (errno) {
76  case EINTR:
77  case ENOBUFS:
78  case ENOMEM:
79  done = 0;
80  break;
81  case (EAGAIN|EWOULDBLOCK):
82  done = -1;
83  break;
84  default:
85  done = -1;
86  break;
87  }
88  }
89  break;
90 
91  case SSL_ERROR_SSL:
92  {
93  unsigned long err;
94 
95  while (0 != (err = ERR_get_error())) {
96  loggerLog(
97  logger,
99  ERR_error_string(err, NULL));
100  }
101  }
102  // DROP THROUGH
103 
104  case SSL_ERROR_ZERO_RETURN:
105  done = -2;
106  break;
107  }
108  }
109 
110  break;
111 
112  default:
113  done = -2;
114  break;
115  }
116 
117  return done;
118 }
Logger logger
Definition: taskrambler.c:66
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ssize_t streamWrite ( Stream  ,
void *  ,
size_t   
)
Todo:
I got a segfault in this call under unclear circumstances. Most likely it has to do with a write on a closed connection.

Definition at line 35 of file stream/write.c.

References logger, LOGGER_DEBUG, loggerLog(), STREAM_FD, and STREAM_SSL.

Referenced by httpWriterWrite().

36 {
37  ssize_t done;
38 
39  switch(this->type) {
40  ssize_t written;
41 
42  case STREAM_FD:
43  written = write((this->handle).fd, buf, count);
44 
45  if (written < 0) {
46  switch (errno) {
47  case EINTR:
48  case ENOBUFS:
49  case ENOMEM:
50  done = 0;
51  break;
52  case (EAGAIN|EWOULDBLOCK):
53  done = -1;
54  break;
55  default:
56  done = -2;
57  break;
58  }
59  } else {
60  done = written;
61  }
62 
63  break;
64 
65  case STREAM_SSL:
66  /**
67  * \todo I got a segfault in this call under unclear
68  * circumstances. Most likely it has to do with a
69  * write on a closed connection.
70  */
71  done = SSL_write((this->handle).ssl, buf, count);
72 
73  if (0 == done) {
74  done = -2;
75  } else if (0 > done) {
76  switch (SSL_get_error((this->handle).ssl, done)) {
77  case SSL_ERROR_SYSCALL:
78  {
79  switch (errno) {
80  case EINTR:
81  case ENOBUFS:
82  case ENOMEM:
83  done = 0;
84  break;
85  case (EAGAIN|EWOULDBLOCK):
86  done = -1;
87  break;
88  default:
89  done = -2;
90  break;
91  }
92  }
93  break;
94 
95  case SSL_ERROR_SSL:
96  {
97  unsigned long err;
98 
99  while (0 != (err = ERR_get_error())) {
100  loggerLog(
101  logger,
102  LOGGER_DEBUG,
103  ERR_error_string(err, NULL));
104  }
105  }
106  // DROP THROUGH
107 
108  case SSL_ERROR_ZERO_RETURN:
109  done = -2;
110  break;
111  }
112  }
113 
114  break;
115 
116  default:
117  done = -2;
118  break;
119  }
120 
121  return done;
122 }
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38
Logger logger
Definition: taskrambler.c:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function: