| | |
| | | #include "socket_io.h" |
| | | #include <stdint.h> |
| | | |
| | | ssize_t rio_readpkgb(rio_t *rp, char *usrbuf, size_t maxlen) |
| | | ssize_t rio_read_until_sep(rio_t *rp, char *usrbuf, size_t maxlen, const char *sep) |
| | | { |
| | | int n, rc; |
| | | char c; |
| | | char *bufp = usrbuf; |
| | | int pkg_sep_i = 0; |
| | | int pkg_sep_len = strlen(PKG_SEP); |
| | | const char * pkg_sep = PKG_SEP; |
| | | int sep_i = 0; |
| | | int sep_len = strlen(sep); |
| | | |
| | | for (n = 0; n < maxlen; n++) |
| | | { |
| | |
| | | |
| | | *bufp++ = c; |
| | | |
| | | if(c == *(pkg_sep + pkg_sep_i)) { |
| | | pkg_sep_i++; |
| | | if(pkg_sep_i == pkg_sep_len) { |
| | | if(c == *(sep + sep_i)) { |
| | | sep_i++; |
| | | if(sep_i == sep_len) { |
| | | |
| | | break; |
| | | } |
| | | } else { |
| | | |
| | | pkg_sep_i = 0; |
| | | sep_i = 0; |
| | | } |
| | | |
| | | } |
| | |
| | | return -1; /* Error */ |
| | | } |
| | | |
| | | if(pkg_sep_i == pkg_sep_len) { |
| | | *(bufp - pkg_sep_len) = 0; |
| | | return n - pkg_sep_len; |
| | | if(sep_i == sep_len) { |
| | | *(bufp - sep_len) = 0; |
| | | return n - sep_len; |
| | | } else { |
| | | return -1; |
| | | } |