Skip to content

Commit 70e8931

Browse files
authored
transport: remove useless trampoline function (#7801)
1 parent ef0f617 commit 70e8931

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

clientconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ func (ac *addrConn) createTransport(ctx context.Context, addr resolver.Address,
13711371
defer cancel()
13721372
copts.ChannelzParent = ac.channelz
13731373

1374-
newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, addr, copts, onClose)
1374+
newTr, err := transport.NewHTTP2Client(connectCtx, ac.cc.ctx, addr, copts, onClose)
13751375
if err != nil {
13761376
if logger.V(2) {
13771377
logger.Infof("Creating new client transport to %q: %v", addr, err)

internal/transport/http2_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ func isTemporary(err error) bool {
199199
return true
200200
}
201201

202-
// newHTTP2Client constructs a connected ClientTransport to addr based on HTTP2
202+
// NewHTTP2Client constructs a connected ClientTransport to addr based on HTTP2
203203
// and starts to receive messages on it. Non-nil error returns if construction
204204
// fails.
205-
func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts ConnectOptions, onClose func(GoAwayReason)) (_ *http2Client, err error) {
205+
func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts ConnectOptions, onClose func(GoAwayReason)) (_ ClientTransport, err error) {
206206
scheme := "http"
207207
ctx, cancel := context.WithCancel(ctx)
208208
defer func() {

internal/transport/transport.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"google.golang.org/grpc/mem"
4040
"google.golang.org/grpc/metadata"
4141
"google.golang.org/grpc/peer"
42-
"google.golang.org/grpc/resolver"
4342
"google.golang.org/grpc/stats"
4443
"google.golang.org/grpc/status"
4544
"google.golang.org/grpc/tap"
@@ -725,12 +724,6 @@ type ConnectOptions struct {
725724
BufferPool mem.BufferPool
726725
}
727726

728-
// NewClientTransport establishes the transport with the required ConnectOptions
729-
// and returns it to the caller.
730-
func NewClientTransport(connectCtx, ctx context.Context, addr resolver.Address, opts ConnectOptions, onClose func(GoAwayReason)) (ClientTransport, error) {
731-
return newHTTP2Client(connectCtx, ctx, addr, opts, onClose)
732-
}
733-
734727
// Options provides additional hints and information for message
735728
// transmission.
736729
type Options struct {

internal/transport/transport_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func setUpWithOptions(t *testing.T, port int, sc *ServerConfig, ht hType, copts
465465
copts.ChannelzParent = channelzSubChannel(t)
466466

467467
connectCtx, cancel := context.WithDeadline(context.Background(), time.Now().Add(2*time.Second))
468-
ct, connErr := NewClientTransport(connectCtx, context.Background(), addr, copts, func(GoAwayReason) {})
468+
ct, connErr := NewHTTP2Client(connectCtx, context.Background(), addr, copts, func(GoAwayReason) {})
469469
if connErr != nil {
470470
cancel() // Do not cancel in success path.
471471
t.Fatalf("failed to create transport: %v", connErr)
@@ -496,7 +496,7 @@ func setUpWithNoPingServer(t *testing.T, copts ConnectOptions, connCh chan net.C
496496
connCh <- conn
497497
}()
498498
connectCtx, cancel := context.WithDeadline(context.Background(), time.Now().Add(2*time.Second))
499-
tr, err := NewClientTransport(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
499+
tr, err := NewHTTP2Client(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
500500
if err != nil {
501501
cancel() // Do not cancel in success path.
502502
// Server clean-up.
@@ -1353,23 +1353,23 @@ func (s) TestClientHonorsConnectContext(t *testing.T) {
13531353

13541354
parent := channelzSubChannel(t)
13551355
copts := ConnectOptions{ChannelzParent: parent}
1356-
_, err = NewClientTransport(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
1356+
_, err = NewHTTP2Client(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
13571357
if err == nil {
1358-
t.Fatalf("NewClientTransport() returned successfully; wanted error")
1358+
t.Fatalf("NewHTTP2Client() returned successfully; wanted error")
13591359
}
1360-
t.Logf("NewClientTransport() = _, %v", err)
1360+
t.Logf("NewHTTP2Client() = _, %v", err)
13611361
if time.Since(timeBefore) > 3*time.Second {
1362-
t.Fatalf("NewClientTransport returned > 2.9s after context cancellation")
1362+
t.Fatalf("NewHTTP2Client returned > 2.9s after context cancellation")
13631363
}
13641364

13651365
// Test context deadline.
13661366
connectCtx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond)
13671367
defer cancel()
1368-
_, err = NewClientTransport(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
1368+
_, err = NewHTTP2Client(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
13691369
if err == nil {
1370-
t.Fatalf("NewClientTransport() returned successfully; wanted error")
1370+
t.Fatalf("NewHTTP2Client() returned successfully; wanted error")
13711371
}
1372-
t.Logf("NewClientTransport() = _, %v", err)
1372+
t.Logf("NewHTTP2Client() = _, %v", err)
13731373
}
13741374

13751375
func (s) TestClientWithMisbehavedServer(t *testing.T) {
@@ -1445,7 +1445,7 @@ func (s) TestClientWithMisbehavedServer(t *testing.T) {
14451445

14461446
parent := channelzSubChannel(t)
14471447
copts := ConnectOptions{ChannelzParent: parent}
1448-
ct, err := NewClientTransport(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
1448+
ct, err := NewHTTP2Client(connectCtx, context.Background(), resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayReason) {})
14491449
if err != nil {
14501450
t.Fatalf("Error while creating client transport: %v", err)
14511451
}
@@ -2436,7 +2436,7 @@ func (ac *attrTransportCreds) Clone() credentials.TransportCredentials {
24362436
}
24372437

24382438
// TestClientHandshakeInfo adds attributes to the resolver.Address passes to
2439-
// NewClientTransport and verifies that these attributes are received by the
2439+
// NewHTTP2Client and verifies that these attributes are received by the
24402440
// transport credential handshaker.
24412441
func (s) TestClientHandshakeInfo(t *testing.T) {
24422442
server := setUpServerOnly(t, 0, &ServerConfig{}, pingpong)
@@ -2458,9 +2458,9 @@ func (s) TestClientHandshakeInfo(t *testing.T) {
24582458
TransportCredentials: creds,
24592459
ChannelzParent: channelzSubChannel(t),
24602460
}
2461-
tr, err := NewClientTransport(ctx, ctx, addr, copts, func(GoAwayReason) {})
2461+
tr, err := NewHTTP2Client(ctx, ctx, addr, copts, func(GoAwayReason) {})
24622462
if err != nil {
2463-
t.Fatalf("NewClientTransport(): %v", err)
2463+
t.Fatalf("NewHTTP2Client(): %v", err)
24642464
}
24652465
defer tr.Close(fmt.Errorf("closed manually by test"))
24662466

@@ -2471,7 +2471,7 @@ func (s) TestClientHandshakeInfo(t *testing.T) {
24712471
}
24722472

24732473
// TestClientHandshakeInfoDialer adds attributes to the resolver.Address passes to
2474-
// NewClientTransport and verifies that these attributes are received by a custom
2474+
// NewHTTP2Client and verifies that these attributes are received by a custom
24752475
// dialer.
24762476
func (s) TestClientHandshakeInfoDialer(t *testing.T) {
24772477
server := setUpServerOnly(t, 0, &ServerConfig{}, pingpong)
@@ -2499,9 +2499,9 @@ func (s) TestClientHandshakeInfoDialer(t *testing.T) {
24992499
Dialer: dialer,
25002500
ChannelzParent: channelzSubChannel(t),
25012501
}
2502-
tr, err := NewClientTransport(ctx, ctx, addr, copts, func(GoAwayReason) {})
2502+
tr, err := NewHTTP2Client(ctx, ctx, addr, copts, func(GoAwayReason) {})
25032503
if err != nil {
2504-
t.Fatalf("NewClientTransport(): %v", err)
2504+
t.Fatalf("NewHTTP2Client(): %v", err)
25052505
}
25062506
defer tr.Close(fmt.Errorf("closed manually by test"))
25072507

@@ -2759,7 +2759,7 @@ func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
27592759
}
27602760
}()
27612761

2762-
ct, err := NewClientTransport(ctx, ctx, resolver.Address{Addr: lis.Addr().String()}, ConnectOptions{}, func(GoAwayReason) {})
2762+
ct, err := NewHTTP2Client(ctx, ctx, resolver.Address{Addr: lis.Addr().String()}, ConnectOptions{}, func(GoAwayReason) {})
27632763
if err != nil {
27642764
t.Fatalf("Error while creating client transport: %v", err)
27652765
}
@@ -2827,7 +2827,7 @@ func (s) TestClientCloseReturnsAfterReaderCompletes(t *testing.T) {
28272827

28282828
// Create a client transport with a custom dialer that hangs the Read()
28292829
// after Close().
2830-
ct, err := NewClientTransport(ctx, context.Background(), addr, copts, func(GoAwayReason) {})
2830+
ct, err := NewHTTP2Client(ctx, context.Background(), addr, copts, func(GoAwayReason) {})
28312831
if err != nil {
28322832
t.Fatalf("Failed to create transport: %v", err)
28332833
}
@@ -2914,7 +2914,7 @@ func (s) TestClientCloseReturnsEarlyWhenGoAwayWriteHangs(t *testing.T) {
29142914
copts := ConnectOptions{Dialer: dialer}
29152915
copts.ChannelzParent = channelzSubChannel(t)
29162916
// Create client transport with custom dialer
2917-
ct, connErr := NewClientTransport(connectCtx, context.Background(), addr, copts, func(GoAwayReason) {})
2917+
ct, connErr := NewHTTP2Client(connectCtx, context.Background(), addr, copts, func(GoAwayReason) {})
29182918
if connErr != nil {
29192919
t.Fatalf("failed to create transport: %v", connErr)
29202920
}

0 commit comments

Comments
 (0)