TosClient provides a series of interfaces for interacting with the TOS service, enabling management of resources such as buckets and objects on the TOS service. TosClient can be initialized using methods such as AccessKey/SecretKey, STS (Security Token Service), etc. During initialization, you can configure optional parameters such as the connection establishment timeout and the maximum number of idle connections. This article describes how to initialize the TOS C SDK.
Prerequisites
Configure Long-Term Access Credential
Before initializing the SDK, you must first configure long-term access credentials. This chapter describes the steps for configuring long-term access credentials on different operating systems.
tip
The use of the C SDK on Windows systems is currently not supported.
- Open the terminal and execute the following command to open the file.
- Add AKSK information at the end of the file.
- Execute the following command to make the configuration information take effect.
- Execute the following command to verify the configuration information.
If the configuration is successful, the following example is returned:
- Open the terminal and execute the following command to open the file.
- Add AKSK information at the end of the file.
- Execute the following commands to make the configuration information take effect.
- Execute the following command to verify the configuration information.
If the configuration is successful, the following example will be returned:
Create TosClient
Initialize with required parameters
The following code demonstrates how to initialize TosClient using required parameters such as the TOS domain name, AK, SK, Endpoint, and Region.
tip
- Endpoint is the access domain name for TOS external services. For information about endpoints supported by TOS, see Access Domain Endpoint.
Initialize Using Optional Parameters
The TOS C SDK provides multiple optional parameters to customize the configuration of TosClient. The following code demonstrates how to customize the connection establishment timeout and read/write timeout settings for TosClient.
Common Configuration Scenarios
Configure Timeout Mechanism
In the SDK, the timeout duration can be adjusted using optional parameters, and the timeout parameters can be configured through the following functions:
- connect_timeout: Specifies the connection timeout, which is the maximum wait time during the connection establishment phase, measured in seconds. The default value is 10, meaning 10 seconds.
- SetSocketTimeout: Sets the timeout for reading and writing network streams, specifying the maximum wait time for a single Read/Write operation in seconds. The default value is 120, that is, 120 seconds.
The following code demonstrates how to set the SDK timeout.
Initialization Parameter List