@@ -116,6 +116,8 @@ type options struct {
116116 keepalivePolicy keepalive.EnforcementPolicy
117117 initialWindowSize int32
118118 initialConnWindowSize int32
119+ writeBufferSize int
120+ readBufferSize int
119121}
120122
121123var defaultServerOptions = options {
@@ -126,6 +128,22 @@ var defaultServerOptions = options{
126128// A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
127129type ServerOption func (* options )
128130
131+ // WriteBufferSize lets you set the size of write buffer, this determines how much data can be batched
132+ // before doing a write on the wire.
133+ func WriteBufferSize (s int ) ServerOption {
134+ return func (o * options ) {
135+ o .writeBufferSize = s
136+ }
137+ }
138+
139+ // ReadBufferSize lets you set the size of read buffer, this determines how much data can be read at most
140+ // for one read syscall.
141+ func ReadBufferSize (s int ) ServerOption {
142+ return func (o * options ) {
143+ o .readBufferSize = s
144+ }
145+ }
146+
129147// InitialWindowSize returns a ServerOption that sets window size for stream.
130148// The lower bound for window size is 64K and any value smaller than that will be ignored.
131149func InitialWindowSize (s int32 ) ServerOption {
@@ -524,6 +542,8 @@ func (s *Server) serveHTTP2Transport(c net.Conn, authInfo credentials.AuthInfo)
524542 KeepalivePolicy : s .opts .keepalivePolicy ,
525543 InitialWindowSize : s .opts .initialWindowSize ,
526544 InitialConnWindowSize : s .opts .initialConnWindowSize ,
545+ WriteBufferSize : s .opts .writeBufferSize ,
546+ ReadBufferSize : s .opts .readBufferSize ,
527547 }
528548 st , err := transport .NewServerTransport ("http2" , c , config )
529549 if err != nil {
0 commit comments