Skip to content

Commit 73ba9a5

Browse files
committed
double the buffer size
1 parent 936ea73 commit 73ba9a5

File tree

10 files changed

+24
-15
lines changed

10 files changed

+24
-15
lines changed

client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
# response = requests.post(url, data=data)
1111
headers = {'Content-Type': 'application/octet-stream'}
1212

13-
nbyte = 100
13+
nbyte = 128
1414

15+
# for i in range(4):
1516
for i in range(4):
1617
nbyte = 10*nbyte
1718
data = bytes([0x0A] * nbyte)

external/gojo/bufio/bufio.mojo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from ..strings import StringBuilder
55

66
alias MIN_READ_BUFFER_SIZE = 16
77
alias MAX_CONSECUTIVE_EMPTY_READS = 100
8-
alias DEFAULT_BUF_SIZE = 4096
8+
alias DEFAULT_BUF_SIZE = 8200
99

1010
alias ERR_INVALID_UNREAD_BYTE = "bufio: invalid use of unread_byte"
1111
alias ERR_INVALID_UNREAD_RUNE = "bufio: invalid use of unread_rune"
@@ -93,7 +93,7 @@ struct Reader[R: io.Reader](Sized, io.Reader, io.ByteReader, io.ByteScanner):
9393
self.read_pos = 0
9494

9595
# Compares to the length of the entire List[UInt8] object, including 0 initialized positions.
96-
# IE. var b = List[UInt8](capacity=4096), then trying to write at b[4096] and onwards will fail.
96+
# IE. var b = List[UInt8](capacity=8200), then trying to write at b[8200] and onwards will fail.
9797
if self.write_pos >= self.buf.capacity:
9898
panic("bufio.Reader: tried to fill full buffer")
9999

@@ -444,7 +444,7 @@ struct Reader[R: io.Reader](Sized, io.Reader, io.ByteReader, io.ByteScanner):
444444
var err = Error()
445445
var full_buffers = List[List[UInt8]]()
446446
var total_len = 0
447-
var frag = List[UInt8](capacity=4096)
447+
var frag = List[UInt8](capacity=8200)
448448
while True:
449449
frag, err = self.read_slice(delim)
450450
if not err:

external/gojo/bufio/scan.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ alias ERR_FINAL_TOKEN = Error("final token")
311311
# The actual maximum token size may be smaller as the buffer
312312
# may need to include, for instance, a newline.
313313
alias MAX_SCAN_TOKEN_SIZE = 64 * 1024
314-
alias START_BUF_SIZE = 4096 # Size of initial allocation for buffer.
314+
alias START_BUF_SIZE = 8200 # Size of initial allocation for buffer.
315315

316316

317317
fn new_scanner[R: io.Reader](owned reader: R) -> Scanner[R]:

external/gojo/io/io.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from collections.optional import Optional
22
from ..builtins import cap, copy, Byte, panic
33
from .traits import ERR_UNEXPECTED_EOF
44

5-
alias BUFFER_SIZE = 4096
5+
alias BUFFER_SIZE = 8200
66

77

88
fn write_string[W: Writer](inout writer: W, string: String) -> (Int, Error):

external/gojo/net/net.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from ..builtins import Byte
44
from .socket import Socket
55
from .address import Addr, TCPAddr
66

7-
alias DEFAULT_BUFFER_SIZE = 4096
7+
alias DEFAULT_BUFFER_SIZE = 8200
88

99

1010
trait Conn(io.Writer, io.Reader, io.Closer):

external/gojo/net/tcp.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from .socket import Socket
77

88
# Time in nanoseconds
99
alias Duration = Int
10-
alias DEFAULT_BUFFER_SIZE = 4096
10+
alias DEFAULT_BUFFER_SIZE = 8200
1111
alias DEFAULT_TCP_KEEP_ALIVE = Duration(15 * 1000 * 1000 * 1000) # 15 seconds
1212

1313

external/gojo/strings/builder.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct StringBuilder[growth_factor: Float32 = 2](Stringable, Sized, io.Writer, i
3333
var capacity: Int
3434

3535
@always_inline
36-
fn __init__(inout self, *, capacity: Int = 4096):
36+
fn __init__(inout self, *, capacity: Int = 8200):
3737
constrained[growth_factor >= 1.25]()
3838
self.data = DTypePointer[DType.uint8]().alloc(capacity)
3939
self.size = 0

lightbug_http/http.mojo

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ fn encode(res: HTTPResponse) raises -> String:
357357
_ = builder.write_string(len(res.body_raw).__str__())
358358
_ = builder.write_string(rChar)
359359
_ = builder.write_string(nChar)
360+
else:
361+
_ = builder.write_string("Content-Length: 0")
362+
_ = builder.write_string(rChar)
363+
_ = builder.write_string(nChar)
360364

361365
_ = builder.write_string("Connection: ")
362366
if res.connection_close():
@@ -369,11 +373,12 @@ fn encode(res: HTTPResponse) raises -> String:
369373
_ = builder.write_string("Date: ")
370374
_ = builder.write_string(current_time)
371375

376+
_ = builder.write_string(rChar)
377+
_ = builder.write_string(nChar)
378+
_ = builder.write_string(rChar)
379+
_ = builder.write_string(nChar)
380+
372381
if len(res.body_raw) > 0:
373-
_ = builder.write_string(rChar)
374-
_ = builder.write_string(nChar)
375-
_ = builder.write_string(rChar)
376-
_ = builder.write_string(nChar)
377382
_ = builder.write(res.get_body_bytes())
378383

379384
return StringSlice[False, ImmutableStaticLifetime](unsafe_from_utf8_ptr=builder.render().unsafe_ptr(), len=builder.size)

lightbug_http/net.mojo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from external.libc import (
1414
inet_ntop
1515
)
1616

17-
alias default_buffer_size = 4096
17+
alias default_buffer_size = 8200
1818
alias default_tcp_keep_alive = Duration(15 * 1000 * 1000 * 1000) # 15 seconds
1919

2020

@@ -270,6 +270,7 @@ fn get_peer_name(fd: Int32) raises -> HostPort:
270270
"""Return the address of the peer connected to the socket."""
271271
var remote_address_ptr = UnsafePointer[sockaddr].alloc(1)
272272
var remote_address_ptr_size = socklen_t(sizeof[sockaddr]())
273+
273274
var status = getpeername(
274275
fd,
275276
remote_address_ptr,

lightbug_http/sys/server.mojo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ struct SysServer:
165165
"""
166166
var b = Bytes()
167167
_ = conn.read(b)
168+
if len(b) == 0:
169+
conn.close()
170+
return
168171

169172
var buf = buffer.new_buffer(b)
170173
var reader = Reader(buf)
@@ -219,7 +222,6 @@ struct SysServer:
219222
except e:
220223
error = Error("Failed to read request body: " + e.__str__())
221224

222-
print(encode(request))
223225
var res = handler.func(request)
224226

225227
# if not self.tcp_keep_alive:

0 commit comments

Comments
 (0)