Based on project requirements:
This section describes the loader and network modules:
The loader module is a customer of the network module. The network module provides the function of obtaining and uploading resources. The obtained resources may come from the network, local files, or cache.
The resourcehandleclient class under the network directory is the customer of the resourcehandle class. It defines virtual functions of some columns. These virtual functions are the callback of resourcehandle, and the inheritance class implements these interfaces. The resourcehandleclient class is an interface provided by the network module to other modules. Other modules can inherit this class, implement virtual functions in it, and then interact with the network module.
The resourcehandleclient interface is closely related to the network transmission process. Generally, it is the callback corresponding to a network event. The following are some of the interfaces:
Void willsendrequest (resourcehandle *, resourcerequest &, const resourceresponse &/* redirectresponse */)
// Generally, you can set a specific HTTP header, such as the user agent, to be called before initiating a network request. It is also automatically called during redirect requests.
Void didsenddata (resourcehandle *, unsigned long/* bytessent */, unsigned lOng/* totalbytestobesent */)
// When uploading data, it is called when the TCP write event sends data to the other party. loader can display the upload progress based on this callback.
Void didreceiveresponse (resourcehandle *, const resourceresponse &)
// After receiving the first response packet, at least the HTTP header has been parsed, And the loader determines whether the request is successful based on the response header information.
Void didreceivedata (resourcehandle *, const char *, Int, INT/* encodeddatalength */)
// Receives the HTTP Response Data, similar to the TCP read event, to respond to HTTP data. The network is designed to upload a piece of data.
Void didfinishloading (resourcehandle *, double/* finishtime */)
// The load is complete and the data has been fully received.
Void didfail (resourcehandle *, const resourceerror &)
// Loading failed
Void didreceiveauthenticationchallenge (resourcehandle *, const authenticationchallenge &)
// Requires user authentication