buffer.c


Log

Author Commit Date CI Message
Nick Mathewson 539466e5 2012-02-10T17:33:50 Merge remote-tracking branch 'origin/patches-2.0' Conflicts: Makefile.am WIN32-Code/event2/event-config.h configure.in
Nick Mathewson e49e2891 2012-02-10T17:29:53 Update copyright notices to 2012
Nick Mathewson 4dee4cc7 2012-02-02T11:45:23 Replace more C99/C++ comments with oldschool /* */ comments
Nick Mathewson 5683e2b1 2012-01-20T16:31:20 Merge remote-tracking branch 'github/linked_list' Conflicts: include/event2/event_struct.h
Nick Mathewson cac02fad 2011-12-08T14:38:04 Merge remote-tracking branch 'origin/patches-2.0'
Zack Weinberg c986f232 2011-12-08T14:30:20 Fix behavior of evbuffer_peek(buf,-1,NULL,NULL,0) (Patch altered by nickm to not affect the behavior of evbuffer_peek(buf,-1,NULL,vec,n_vec).)
Nick Mathewson 5c7675cc 2011-12-08T14:05:47 whitespace fixes
Nick Mathewson de5428e7 2011-12-08T14:04:04 Merge remote-tracking branch 'fancycode/buffer_references' Conflicts: buffer.c
Joachim Bauch a8e5e2fc 2011-12-07T21:06:10 Changed use of refcounts to make sure referenced chains are freed in all cases.
Nick Mathewson 27e22255 2011-12-07T13:04:35 Add evbuffer_copyout_from to copy data from the middle of a buffer You could previously do this with evbuffer_peek() and some memcpys, but it was a bit more work than most folks wanted to get into. Closes sourceforge ticket 3108072
Nick Mathewson da45aa74 2011-12-02T01:48:14 fix windows compilation issues with new file segment code Found by Linus Nordberg
Andrea Montefusco d7a8b36e 2011-11-14T11:42:52 New EVBUFFER_EOL_NUL to read NUL-terminated strings from an evbuffer
Nick Mathewson 27b5398f 2011-11-11T17:56:08 Tweaks, fixups, and comments on evbuffer_add_iovec
Mark Ellzey aaec5aca 2011-10-25T09:13:15 Added evbuffer_add_iovec and unit tests.
Nick Mathewson dea055d0 2011-11-02T23:15:07 Merge remote-tracking branch 'github/20_evbuffer_remove_bug'
Nick Mathewson c882a959 2011-11-02T23:14:24 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson b18c04dd 2011-11-02T22:50:47 Use the free-trailing-chains function in evbuffer_insert_chain too
Nick Mathewson c37069cd 2011-11-02T16:09:15 Fix an evbuffer crash in evbuffer_remove_buffer() Found by Greg Hazel.
Nick Mathewson 0cb70e33 2011-10-26T10:17:21 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 3c824bd3 2011-10-24T13:18:09 Update copyright dates to 2011.
Joachim Bauch 95a8b87a 2011-10-17T21:48:23 fixed typo
Joachim Bauch ba24f616 2011-10-17T21:46:12 added comments to describe refcounting of multicase chains
Nick Mathewson c6bbbf1b 2011-10-06T18:02:22 Make evbuffer_file_segment_types adaptable Instead of having a file segment born as one type and stay that way forever, let them start out unmapped, but map themselves as needed if they need to get written out on a non-drains_to_fd evbuffer.
Nick Mathewson 83588777 2011-10-06T15:21:55 Merge remote-tracking branch 'origin/patches-2.0' Conflicts: buffer.c test/regress_buffer.c
Nick Mathewson 0ba0af9c 2011-09-29T09:30:04 Prefer mmap to sendfile unless a DRAINS_TO_FD flag is set. Allows add_file to work with SSL. The sendfile() implementation for evbuffer_add_file is potentially more efficient, but it has a problem: you can only use it to send bytes over a socket using sendfile(). If you are writing bytes via SSL_send() or via a filter, or if you need to be able to inspect your buffer, it doesn't work. As an easy fix, this patch disables the sendfile-based implementation of evbuffer_add_file on an evbuffer unless the user sets a new EVBUFFER_FLAG_DRAINS_TO_FD flag on that evbuffer, indicating that the evbuffer will not be inspected, but only written out via evbuffer_write(), evbuffer_write_atmost(), or drained with stuff like evbuffer_drain() or evbuffer_add_buffer(). This flag is off by default, except for evbuffers used for output on bufferevent_socket. In the future, it could be interesting to make a best-effort file segment implementation that tries to send via sendfile, but mmaps on demand. That's too much complexity for a stable release series, though.
Nick Mathewson 46974cd8 2011-09-28T09:23:41 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 1ef1f684 2011-09-28T09:22:17 Make evbuffer callbacks get the right n_added value after evbuffer_add Patch from Alex.
Nick Mathewson 0d108044 2011-08-18T15:18:14 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 6acfbdd8 2011-08-18T12:35:27 Make overlapped reads result in evbuffer callbacks getting invoked
Nick Mathewson ec670c15 2011-08-17T22:08:06 Merge remote-tracking branch 'origin/patches-2.0' Conflict in buffer.c: the new file-segment logic conflicted with the solaris sendfile fix.
Michael Herf 643922e9 2011-08-15T13:39:10 Solaris sendfile: correctly detect amount of data sent Original message: Solaris sendfile seems to fail when sending moderately large (<1GB) files. Not a 32/64 problem, but a buffer problem. Anyone else ever try this? It is definitely broken in http-server.c. It seems to be broken in the following way: When sendfile sends partial data (EAGAIN, would block), "res" is always -1, rather than the amount sent. Here's a patch that reads from the "offset" pointer instead to discover what was sent. This seems to work:
Joachim Bauch 26041a8e 2011-08-04T23:39:15 prevent nested multicast references, reworked locking
Joachim Bauch 9d7368ae 2011-06-09T23:33:58 support adding buffers to other buffers non-destructively
Nick Mathewson 7d08a28c 2011-07-05T15:07:07 Merge remote-tracking branch 'github/21_end_of_buffer' Conflicts: include/event2/buffer.h
Nick Mathewson c3d36285 2011-07-04T11:48:41 Merge remote-tracking branch 'origin/patches-2.0'
Mark Ellzey f87f5689 2011-07-04T11:47:24 Speed up invoke_callbacks on evbuffers when there are no callbacks This fixes a performance regression against 1.4
Nir Soffer e3e97ae3 2011-06-14T01:58:30 Set the special "not found" evbuffer_ptr consistantly. The _internal.pos_in_chain field was uninitialized or set to different values in different places returning the special "not found" pointer. Signed-off-by: Nir Soffer <nirsof@gmail.com>
Nick Mathewson 9ab8ab83 2011-06-13T16:47:43 Tweaks to return types with end-of-buf ptrs
Nir Soffer 7aeb2fd4 2011-06-13T16:35:28 Allow evbuffer_ptr to point to position 0 in an empty evbuffer
Nick Mathewson e6fe1da9 2011-06-06T21:03:35 Allow evbuffer_ptr_set to yield a point just after the end of the buffer.
Nick Mathewson d19a3260 2011-06-08T13:32:47 Remove a needless branch in evbuffer_drain() Found by Gilad Benjamini; see June 2011 thread "Dead or wrong code".
Nick Mathewson d927965f 2011-06-06T15:33:27 Fix a bug in the improved EOL_CRLF code When searching for a CRLF, it would find an LF, then look for a preceding CR if not at the start of the buffer. That's fine when we're starting from the beginning of the buffer, but if we're starting at (say) byte 100, and we have that byte == LF, we shouldn't check for a CR at byte 99.
Nick Mathewson 264c7b96 2011-06-06T15:26:37 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 4461f1a0 2011-06-06T15:11:28 Fix incorrect results from evbuffer_search_eol(EOL_LF) Our evbuffer_strchr() function [which was only used for search_eol(EOL_LF) could give incorrect results if it found its answer in the first chunk but didn't start searching from the front of the chunk. Also, this patch adds unit tests for evbuffer_search_eol, particularly in those cases that evbuffer_readln() tests didn't exercise.
Nick Mathewson 8254de76 2011-06-02T17:07:40 Fix windows file segment mappings Instead of mapping enough bytes for each segment, we were failing to take into account the slop created by rounding the segment position down to the nearest page. Should fix bug 3142394 found by Sebastian Hahn.
Nick Mathewson 7b9d1395 2011-06-01T14:19:13 Try to squeeze a little more speed out of EVBUFFER_EOL_CRLF
Mina Naguib 5dde0f04 2011-05-31T13:56:56 Roughly 20% speed increase when line-draining a buffer using EVBUFFER_EOL_CRLF
Nick Mathewson 9f560bfa 2011-05-25T19:50:56 Use "_WIN32", not WIN32: it's standard and we don't need to fake it This patch was automatically generated with perl. Based on a patch by Peter Rosin.
Nick Mathewson b647e0bc 2011-01-07T12:31:30 Merge remote branch 'kev009/21_ac_use_system_extensions'
Kevin Bowling c13e1859 2011-01-07T00:34:22 Remove use and reference to event-private.h
Kevin Bowling 0915ca0a 2011-01-02T08:43:45 Include evconfig-private.h in internal files for great good.
Kevin Bowling 9b27b307 2011-01-02T08:04:12 Remove event-private.h and switch to evconfig-private.h
Kevin Bowling c51ef930 2010-12-22T23:24:01 Eliminate a couple more manual internal _GNU_SOURCE defines
Nick Mathewson 3f405d2d 2010-10-25T12:29:39 Add CreateFileMapping file_segment implementation for win32
Nick Mathewson c2d9884a 2010-10-25T12:10:10 Add support for mmaps with nonzero offset values. Needs testing.
Nick Mathewson e72afae0 2010-10-21T19:45:49 Add evbuffer_add_file_segment() so one fd can be used efficiently in more than one evbuffer_add_file at a time
Evan Jones b63ab177 2010-12-06T14:17:44 EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings.
Nick Mathewson bb0d2b4e 2010-12-09T11:47:54 Consistentize tabs
Nick Mathewson 7bcace2d 2010-11-22T21:02:34 Fix some irix compilation warnings spotted by Kevin Bowling
Nick Mathewson a3245afe 2010-11-01T14:23:33 Fix win32 build in response to fixes from win64 build.
Nick Mathewson 545a6114 2010-11-01T13:59:04 Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc
Nick Mathewson e4f34e8a 2010-10-25T22:36:23 Correct logic for realigning a chain in evbuffer_add The old logic was both too eager to realign (it would move a whole chain to save a byte) and too reluctant to realign (it would only realign when data would fit into the misaligned portion, without considering the space at the end of the chain). The new logic matches that from evbuffer_expand_singlechain: it only realigns a chain when not much data is to be moved, and there's a bunch of space to be regained. Spotted by Yan Lin.
Nick Mathewson ac7e52d8 2010-10-25T14:29:30 Make evbuffer_add_file take ev_off_t, not off_t This change has no effect on non-windows platforms, since those either define off_t to 64-bits, or allow you to decide whether it should be 64-bits yourself via some LARGEFILE-like macro. On Windows, however, off_t is always 32-bit, so it's a bad choice for "file size" or "file offset" values. Instead, I'm adding an ev_off_t type, and using it in the one place where we used off_t to mean "the size of a file" or "an offset into a file" in the API. This breaks ABI compatibility on Windows.
Nick Mathewson 6be589ae 2010-10-14T13:48:40 Fix signed/unsigned warnings on opensolaris, where iov_len is signed
Nick Mathewson fdc640b0 2010-10-05T21:34:07 Fix an EINVAL on evbuffer_write_iovec on OpenSolaris. The writev() call is limited to at most IOV_MAX iovecs (or UIO_MAXIOV, depending on whom you ask). This isn't a problem anywhere we've tested except on OpenSolaris, where IOV_MAX was a mere 16. This patch makes us go from "use up to 128 iovecs when writing" to "use up to 128 iovecs when writing, or IOV_MAX/UIO_MAXIOV, whichever is less". This is still wrong if you somehow find a platform that defines IOV_MAX < UIO_MAXIOV, but I hereby claim that such a platform is too stupid to worry about for now. Found by Michael Herf.
Nick Mathewson 9c8db0f8 2010-09-23T22:45:55 Fix all warnings in the main codebase flagged by -Wsigned-compare Remember, the code int is_less_than(int a, unsigned b) { return a < b; } is buggy, since the C integer promotion rules basically turn it into int is_less_than(int a, unsigned b) { return ((unsigned)a) < b; } and we really want something closer to int is_less_than(int a, unsigned b) { return a < 0 || ((unsigned)a) < b; } . Suggested by an example from Ralph Castain
Christopher Davis 03afa209 2010-08-16T01:23:57 IOCP-related evbuffer fixes. - Prevent evbuffer_{add,prepend}_buffer from moving read-pinned chains. - Fix evbuffer_drain to handle read-pinned chains better. - Raise the limit on WSABUFs from two to MAX_WSABUFS for overlapped reads.
Nick Mathewson 743f8665 2010-08-23T11:48:46 Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off in unit test code
Nick Mathewson ec347b92 2010-07-07T16:45:03 Move event-config.h to include/event2 This change means that all required include files are in event2, and all files not in event2/* are optional.
niks 65abdc20 2010-07-16T09:11:09 Fix wrong sie calculation of iovec buffers when exact=1 The old code had a bug where the 'exact' flag to 1 in _evbuffer_read_setup_vecs would never actually make the iov_len field of the last iovec get truncated. This patch fixes that.
Nick Mathewson 3467f2fa 2010-05-28T15:05:32 Fix logic in correcting high values from FIONREAD The old logic made sense back when buffer.c was an enormous linear buffer, but it doesn't make any sense for the chain-based implementation. This patch also refactors the ioctl{socket}? call into its own function.
Nick Mathewson c44de06c 2010-05-08T18:09:27 Numerous opensolaris compilation fixes For future note, opensolaris doesn't have sys/sysctl.h, doesn't like comparing iov_buf to a chain_space_ptr without a cast, and is (predictably) unforgiving of dumb syntax errors. Also, we had accidentally broken the devpoll backend test in configure.in
Nick Mathewson dcdae6b7 2010-05-08T16:34:18 Make evbuffer_add_file() work on windows Right now only the add_file() mode is supported, when it would be nicer to have mmap support. Perhaps for Libevent 2.1.x.
Nick Mathewson d49b92a8 2010-04-23T23:04:20 Remove one last bug in last_with_datap logic. Found with valgrind
Giuseppe Scrivano d469c503 2010-04-12T12:18:57 Fix compiler warnings under WIN32
Nick Mathewson eb86c8c5 2010-04-12T22:24:54 Add evbuffer_copyout to copy data from an evbuffer without draining The evbuffer_remove() function copies data from the front of an evbuffer into an array of char, and removes the data from the buffer. This function behaves the same, but does not remove the data. This behavior can be handy for lots of protocols, where you want the evbuffer to accumulate data until a complete record has arrived. Lots of people have asked for a function more or less like this, and though it isn't too hard to code one from evbuffer_peek(), it is apparently annoying to do it in every app you write. The evbuffer_peek() function is significantly faster, but it requires that the user be able to handle data in separate extents. This patch also reimplements evbufer_remove() as evbuffer_copyout() followed by evbuffer_drain(). I am reasonably confident that this won't be a performance hit: the memcpy() overhead should dominate the cost of walking the list an extra time.
Nick Mathewson d313c293 2010-04-09T20:04:24 Use LIST rather than TAILQ for evbuffer callbacks There's no reason to traverse these out-of-order, and we never defined the order that you'd get your callbacks on an evbuffer if you happened to add more than one.
Nick Mathewson 8c83e995 2010-04-09T16:40:53 Add more unit tests for evbuffer_expand
Nick Mathewson 06a4443a 2010-04-09T15:28:26 Unit-test every evbuffer_add_file() implementation. Previously, we'd only test the default one, even if the others were still compiled in.
Christopher Davis 28bfed47 2010-04-02T19:08:32 Clean up a mistake in pointer manipulation in evbuffer_remove
Nick Mathewson d5ebcf37 2010-03-30T16:47:37 Rewrite evbuffer_expand and its users The previous evbuffer_expand was not only incorrect; it was inefficient too. On all questions of time vs memory tradeoffs, it chose to burn time in order to avoid wasting memory. The new code tries to be a little more balanced: it only resizes an existing chain when doing so doesn't require too much copying, and when failing to do so would waste a lot of the chain's space. This patch also rewrites evbuffer_chain_insert to work properly with last_with_datap, and adds a few convenience functions to buffer.c.
Nick Mathewson 45068a31 2010-03-31T12:03:43 Fix a memory leak when appending/prepending to a buffer with unused space.
Nick Mathewson 8e227b04 2010-03-27T00:09:25 Make the no_iovecs case of write_atmost compile Apparently nobody had tested it before on a system that had sendfile. Why would you have sendfile and not writev? Perhaps you're trying to test the no-iovecs code to make sure it still works.
Nick Mathewson 96865c47 2010-03-30T12:48:56 Turn the increasingly complex *_CHAIN() macros into functions
Nick Mathewson b7442f8e 2010-03-26T23:18:40 Replace last_with_data with a slightly smarter version To implement evbuffer_expand() properly, you need to be able to replace the last chunk that has data, which means that we need to keep track of the the next pointer pointing to the last_with_data chunk, not the last_with_data chunk itself.
Nick Mathewson cda56abf 2010-03-31T12:29:26 Fix critical bug in evbuffer_write when writev is not available evbuffer_pullup() returns NULL if you try to pull up more bytes than are there. But evbuffer_write_atmost would sometimes ask for more bytes to be pulled up than it had, get a NULL, and fail.
Nick Mathewson c87272b7 2010-03-26T14:51:39 Make evbuffer_prepend handle empty buffers better If the first chunk of a buffer is empty, and we're told to prepend to the buffer, we should be willing to use the entire first chunk. Instead, we were dependent on the value of chunk->misalign.
Nick Mathewson 5c0ebb33 2010-03-26T14:50:45 Do not use evbuffer_expand() to add the first chain to a buffer (It's a big function, and using it this way is overkill.)
Nick Mathewson f1bc125e 2010-03-12T23:00:49 Improve robustness for refcounting Document that we do intend to double-decref underlying bufferevents under some circumstances. Check to make sure that we don't decref past 0.
Nick Mathewson 1e7b9868 2010-03-11T14:23:02 Fix last_with_data compilation on windows
Nick Mathewson e470ad3c 2010-03-10T23:39:30 Allow evbuffer_read() to split across more than 2 iovecs Previously it would only accept 2 iovecs at most, because our previous_to_last nonsense didn't let it take any more. This forced us to do more reallocations in some cases when an extra small malloc would have sufficed.
Nick Mathewson 6f47bd12 2010-03-10T23:28:51 Remove previous_to_last from evbuffer
Nick Mathewson c8ac57f1 2010-03-10T23:24:14 Use last_with_data in place of previous_to_last This actually makes some of the code a lot simpler. The only ones that actually used previous_to_last for anything were reserving and committing space.
Nick Mathewson 2a6d2a1e 2010-03-10T22:16:14 Revise evbuffer to add last_with_data This is the first patch in a series to replace previous_to_last with last_with_data. Currently, we can only use two partially empty chains at the end of an evbuffer, so if we have one with 511 bytes free, and another with 512 bytes free, and we try to do a 1024 byte read, we can't just stick another chain on the end: we need to reallocate the last one. That's stupid and inefficient. Instead, this patch adds a last_with_data pointer to eventually replace previous_to_last. Instead of pointing to the penultimated chain (if any) as previous_to_last does, last_with_data points to the last chain that has any data in it, if any. If all chains are empty, last_with_data points to the first chain. If there are no chains, last_with_data is NULL. The next step is to start using last_with_data everywhere that we currently use previous_to_last. When that's done, we can remove previous_to_last and the code that maintains it.
Nick Mathewson 17efc1cd 2010-03-04T01:25:51 Update all our copyright notices to say "2010"
Nick Mathewson cc1600af 2010-03-02T17:00:06 Improve the speed of evbuffer_readln() This makes some cases of bench_http about 5% faster. Our internal evbuffer_strpbrk() function was overly general (it tried to handle all character sets when we only used it for "\r\n"), and not very efficient (it called memchr once for each character in the buffer until it found a \r or a \n). It actually showed up in some profiles for HTTP testing, since evbuffer_readln() calls it when doing loose CRLF detection. This patch replaces it with a faster implementation.
Nick Mathewson b2fbeb3f 2010-02-22T15:38:23 Make bufferevent_free() clear all callbacks immediately. This should end the family of bugs where we call bufferevent_free() while a pending callback is holding a reference on the bufferevent, and the callback tries to invoke the user callbacks before it releases its own final reference. This means that bufferevent_decref() is now a separate function from bufferevent_free().
Nick Mathewson e5bbd40a 2010-02-18T17:41:15 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson 7116bf23 2010-02-15T21:03:52 Fix two unlocked reads in evbuffer. Some initializers (in evbuffer_read and evbuffer_commit) were reading the last and/or previous_to_last fields without grabbing the evbuffer lock. This may fix a hard-to-trigger race condition or two.
Nick Mathewson 3fe60fdf 2010-02-12T23:40:13 Use off_t for the length parameter of evbuffer_add_file