Project

General

Profile

network_openssl.patch

stbuehler, 2010-01-06 14:12

Download (1.33 KB)

View differences:

patch/src/network_openssl.c 2010-01-02 01:34:07.000000000 +0800
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;
41
	int read_offset;
40 42

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

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

  
49
#define TOREAD_SSL (8192+12)   /* ssl-chunk-size is 8kb */
50

  
51
		toread = TOREAD_SSL;
52
		read_offset = 0;
53

  
54
		if (cq->last && cq->last->mem
55
			&& cq->last->mem->used < cq->last->mem->size) {
56
			b = cq->last->mem;
57
			if (b->used > 0) {
58
				toread = b->size - b->used;
59
				read_offset = b->used - 1;
60
			}
61
			else {
62
				toread = b->size - 1;
63
				read_offset = 0;
64
			}
65
		}
66
		else { 
67
			b = chunkqueue_get_append_buffer(cq);
68
			buffer_prepare_copy(b, TOREAD_SSL+1);
69
		}
70
		
48 71
		ERR_clear_error();
49
		len = SSL_read(sock->ssl, b->ptr, b->size - 1);
72
		len = SSL_read(sock->ssl, b->ptr + read_offset, toread);
50 73

  
51 74
		/**
52 75
		 * man SSL_read:
......
123 146
				return res;
124 147
			}
125 148
		} else {
149
			if (b->used == 0) b->used = 1; /* at first, reserve a position for '\0' */
126 150
			b->used += len;
127
			b->ptr[b->used++] = '\0';
151
			b->ptr[b->used-1] = '\0';
128 152

  
129 153
			read_something = 1;
130 154
			cq->bytes_in += len;