return -1;
}
-#if 0
-/* Find the first occurence of the string_len byte string 'str' on the
- * buffer 'buf'. If none exists, return -1. Otherwise, return index
- * of the first character on the buffer _after_ the first instance of str.
- */
-int find_on_inbuf(char *str, int string_len, buf_t *buf) {
- return find_mem_in_mem(str, string_len, buf->mem, buf->datalen);
-}
-#endif
-
-/* Create and return a new buf with capacity 'capacity'.
+/* Create and return a new buf with capacity 'size'.
*/
buf_t *buf_new_with_capacity(size_t size) {
buf_t *buf;
/* Write data from 'buf' to the socket 's'. Write at most
* *buf_flushlen bytes, and decrement *buf_flushlen by the number of
* bytes actually written. Return the number of bytes written on
- * success, -1 on failure. Returns 0 if write() would block.
+ * success, -1 on failure. Return 0 if write() would block.
*/
int flush_buf(int s, buf_t *buf, int *buf_flushlen)
{
/* Remove string_len bytes from the front of 'buf', and store them
- * into 'string'. Returns the new buffer size. string_len must be <=
+ * into 'string'. Return the new buffer size. string_len must be <=
* the number of bytes on the buffer.
*/
int fetch_from_buf(char *string, size_t string_len, buf_t *buf) {
return fetch_from_buf(string, len, conn->inbuf);
}
-/*
-int connection_find_on_inbuf(char *string, int len, connection_t *conn) {
- return find_on_inbuf(string, len, conn->inbuf);
-}
-*/
-
int connection_wants_to_flush(connection_t *conn) {
return conn->outbuf_flushlen;
}
/********************************* buffers.c ***************************/
-/* int find_on_inbuf(char *string, int string_len, buf_t *buf); */
-
buf_t *buf_new();
buf_t *buf_new_with_capacity(size_t size);
void buf_free(buf_t *buf);
int connection_read_to_buf(connection_t *conn);
int connection_fetch_from_buf(char *string, int len, connection_t *conn);
-/* int connection_find_on_inbuf(char *string, int len, connection_t *conn); */
int connection_wants_to_flush(connection_t *conn);
int connection_outbuf_too_full(connection_t *conn);
close(s);
-
-#if 0
- /****
- * find_on_inbuf
- ****/
- buf_free(buf);
- buf = buf_new();
- s = open("/tmp/tor_test/data", O_RDONLY, 0);
- eof = 0;
- i = read_to_buf(s, 1024, buf, &eof);
- test_eq(256, i);
- close(s);
-
- test_eq(((int)'d') + 1, find_on_inbuf("abcd", 4, buf));
- test_eq(-1, find_on_inbuf("xyzzy", 5, buf));
- /* Make sure we don't look off the end of the buffef */
- ((char*)_buf_peek_raw_buffer(buf))[256] = 'A';
- ((char*)_buf_peek_raw_buffer(buf))[257] = 'X';
- test_eq(-1, find_on_inbuf("\xff" "A", 2, buf));
- test_eq(-1, find_on_inbuf("AX", 2, buf));
- /* Make sure we use the string length */
- test_eq(((int)'d')+1, find_on_inbuf("abcdX", 4, buf));
-#endif
-
/****
* fetch_from_buf
****/