-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add streamed processing of bulk, eliminating the limits needed to prevent memory requirements as well as recreation of svrquery.Client for each processed element by implementing a reusable BulkClient. This changes the processing to best effort and can result in entries without an address being output. Also: * Output to a provided stream. * Eliminate the use of log.Fatal in the library. * Include element details when parsing fails.
- Loading branch information
Showing
3 changed files
with
178 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package svrquery | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/multiplay/go-svrquery/lib/svrquery/protocol" | ||
) | ||
|
||
// BulkClient is a client which can be reused with multiple requests. | ||
type BulkClient struct { | ||
client *Client | ||
} | ||
|
||
// NewBulkClient creates a new client with no protocol or | ||
func NewBulkClient(options ...Option) (*BulkClient, error) { | ||
c := &Client{ | ||
network: DefaultNetwork, | ||
timeout: DefaultTimeout, | ||
} | ||
|
||
for _, o := range options { | ||
if err := o(c); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &BulkClient{client: c}, nil | ||
} | ||
|
||
// Query runs a query against addr with proto and options. | ||
func (b *BulkClient) Query(proto, addr string, options ...Option) (protocol.Responser, error) { | ||
f, err := protocol.Get(proto) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, o := range options { | ||
if err := o(b.client); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
b.client.Queryer = f(b.client) | ||
|
||
if b.client.ua, err = net.ResolveUDPAddr(b.client.network, addr); err != nil { | ||
return nil, err | ||
} | ||
|
||
if b.client.c, err = net.DialUDP(b.client.network, nil, b.client.ua); err != nil { | ||
return nil, err | ||
} | ||
|
||
return b.client.Query() | ||
} |