Project

General

Profile

fix-2147-in-1.5.patch

Fix for 1.5 - stbuehler, 2010-01-22 17:47

Download (5.76 KB)

View differences:

src/connections.c
802 802
		} else {
803 803
			buffer *b;
804 804

  
805
			b = chunkqueue_get_append_buffer(out);
805
			b = (out->last) ? out->last->mem : NULL;
806

  
807
			if (NULL == b || b->size - b->used < 1024) {
808
				b = chunkqueue_get_append_buffer(out);
809
				buffer_prepare_copy(b, con->request.content_length - out->bytes_in + 1);
810
			}
811

  
806 812
			buffer_copy_string_len(b, c->mem->ptr + c->offset, toRead);
807 813
		}
808 814

  
src/network_openssl.c
37 37
	off_t max_read = 256 * 1024;
38 38
	off_t start_bytes_in = cq->bytes_in;
39 39
	network_status_t res;
40
	int toread, read_offset;
40 41

  
41 42
	UNUSED(srv);
42 43
	UNUSED(con);
43 44

  
45
	/* use a chunk-size of 4k, append to last buffer if it has >= 1kb free */
46
#define TOREAD 4096
47

  
44 48
	do {
45 49
		int oerrno;
46
		b = chunkqueue_get_append_buffer(cq);
47
		buffer_prepare_copy(b, 8192 + 12); /* ssl-chunk-size is 8kb */
50

  
51
		b = (cq->last) ? cq->last->mem : NULL;
52

  
53
		if (NULL == b || b->size - b->used < 1024) {
54
			b = chunkqueue_get_append_buffer(cq);
55
			buffer_prepare_copy(b, TOREAD+1);
56
		}
57

  
58
		read_offset = (b->used == 0) ? 0 : b->used - 1;
59
		toread = b->size - 1 - read_offset;
60

  
48 61
		ERR_clear_error();
49
		len = SSL_read(sock->ssl, b->ptr, b->size - 1);
62
		len = SSL_read(sock->ssl, b->ptr + read_offset, toread);
50 63

  
51 64
		/**
52 65
		 * man SSL_read:
......
63 76

  
64 77
			switch ((r = SSL_get_error(sock->ssl, len))) {
65 78
			case SSL_ERROR_WANT_READ:
79
			case SSL_ERROR_WANT_WRITE:
66 80
				return read_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_WAIT_FOR_EVENT;
67 81
			case SSL_ERROR_SYSCALL:
68 82
				/**
......
123 137
				return res;
124 138
			}
125 139
		} else {
140
			if (b->used > 0) b->used--;
126 141
			b->used += len;
127 142
			b->ptr[b->used++] = '\0';
128 143

  
......
130 145
			cq->bytes_in += len;
131 146
		}
132 147

  
133
		if (cq->bytes_in - start_bytes_in > max_read) return NETWORK_STATUS_SUCCESS;
134
	} while (1);
148
		if (cq->bytes_in - start_bytes_in > max_read) break;
149
	} while (len == toread);
135 150

  
136
	return NETWORK_STATUS_FATAL_ERROR;
151
	return NETWORK_STATUS_SUCCESS;
137 152
}
138 153

  
139 154

  
src/network_win32_send.c
30 30
*/
31 31
NETWORK_BACKEND_READ(win32recv)
32 32
{
33
	int toread;
33
	int toread, read_offset;
34 34
	buffer *b;
35 35
	off_t r, start_bytes_in;
36 36
	off_t max_read = 256 * 1024;
......
45 45

  
46 46
	start_bytes_in = cq->bytes_in;
47 47

  
48
	/* use a chunk-size of 16k */
48
	/* use a chunk-size of 4k, append to last buffer if it has >= 1kb free */
49
#define TOREAD 4096
50

  
49 51
	do {
50
		toread = 16384;
52
		b = (cq->last) ? cq->last->mem : NULL;
51 53

  
52
		b = chunkqueue_get_append_buffer(cq);
54
		if (NULL == b || b->size - b->used < 1024) {
55
			b = chunkqueue_get_append_buffer(cq);
56
			buffer_prepare_copy(b, TOREAD+1);
57
		}
53 58

  
54
		buffer_prepare_copy(b, toread);
59
		read_offset = (b->used == 0) ? 0 : b->used - 1;
60
		toread = b->size - 1 - read_offset;
55 61

  
56
		if (-1 == (r = recv(sock->fd, b->ptr, toread, 0))) {
62
		if (-1 == (r = recv(sock->fd, b->ptr + read_offset, toread, 0))) {
57 63
			switch (light_sock_errno()) {
58 64
			case EAGAIN:
59 65
			case EWOULDBLOCK:
......
76 82

  
77 83
		read_something = 1;
78 84

  
79
		b->used = r;
85
		if (b->used > 0) b->used--;
86
		b->used += r;
80 87
		b->ptr[b->used++] = '\0';
88

  
81 89
		cq->bytes_in += r;
82 90

  
83 91
		if (cq->bytes_in - start_bytes_in > max_read) break;
84
	} while (r == toread); 
92
	} while (r == toread);
85 93

  
86 94
	return NETWORK_STATUS_SUCCESS;
87 95
}
88 96

  
89
NETWORK_BACKEND_WRITE(win32send) 
97
NETWORK_BACKEND_WRITE(win32send)
90 98
{
91 99
	chunk *c;
92 100
	size_t chunks_written = 0;
src/network_write.c
35 35
* as vectors
36 36
*/
37 37
NETWORK_BACKEND_READ(read) {
38
	int toread;
38
	int toread, read_offset;
39 39
	buffer *b;
40 40
	off_t r, start_bytes_in;
41 41
	off_t max_read = 256 * 1024;
......
50 50

  
51 51
	start_bytes_in = cq->bytes_in;
52 52

  
53
	/* use a chunk-size of 16k */
53
	/* use a chunk-size of 4k, append to last buffer if it has >= 1kb free */
54
#define TOREAD 4096
55

  
54 56
	do {
55
		toread = 16384;
57
		b = (cq->last) ? cq->last->mem : NULL;
56 58

  
57
		b = chunkqueue_get_append_buffer(cq);
59
		if (NULL == b || b->size - b->used < 1024) {
60
			b = chunkqueue_get_append_buffer(cq);
61
			buffer_prepare_copy(b, TOREAD+1);
62
		}
58 63

  
59
		buffer_prepare_copy(b, toread);
64
		read_offset = (b->used == 0) ? 0 : b->used - 1;
65
		toread = b->size - 1 - read_offset;
60 66

  
61
		if (-1 == (r = read(sock->fd, b->ptr, toread))) {
67
		if (-1 == (r = read(sock->fd, b->ptr + read_offset, toread))) {
62 68
			switch (errno) {
63 69
			case EAGAIN:
64 70
				/* remove the last chunk from the chunkqueue */
......
80 86

  
81 87
		read_something = 1;
82 88

  
83
		b->used = r;
89
		if (b->used > 0) b->used--;
90
		b->used += r;
84 91
		b->ptr[b->used++] = '\0';
92

  
85 93
		cq->bytes_in += r;
86 94

  
87 95
		if (cq->bytes_in - start_bytes_in > max_read) break;
88
-