PSP Networking refactor
This commit is contained in:
@@ -6,46 +6,14 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "network/networkhttprequest.h"
|
||||
#include "thread/thread.h"
|
||||
#include "error/error.h"
|
||||
#include <curl/curl.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#define NETWORK_HTTP_PENDING_MAX 16
|
||||
#define NETWORK_HTTP_URL_MAX 512
|
||||
#define NETWORK_HTTP_BODY_MAX 8192
|
||||
#define NETWORK_HTTP_RESPONSE_MAX 65536
|
||||
#define NETWORK_HTTP_HEADER_MAX 16
|
||||
#define NETWORK_HTTP_HEADER_KEY_MAX 64
|
||||
#define NETWORK_HTTP_HEADER_VAL_MAX 256
|
||||
#define NETWORK_ERROR_MESSAGE_MAX 256
|
||||
|
||||
typedef struct {
|
||||
bool_t used;
|
||||
volatile bool_t resultReady;
|
||||
bool_t isError;
|
||||
|
||||
char_t url[NETWORK_HTTP_URL_MAX];
|
||||
networkhttprequestmethod_t method;
|
||||
char_t body[NETWORK_HTTP_BODY_MAX];
|
||||
bool_t hasBody;
|
||||
char_t headerKeys[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_KEY_MAX];
|
||||
char_t headerVals[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_VAL_MAX];
|
||||
uint32_t headerCount;
|
||||
|
||||
networkhttpcallback_t callback;
|
||||
networkhttperrorcallback_t errorCallback;
|
||||
void *user;
|
||||
|
||||
uint16_t status;
|
||||
char_t responseBody[NETWORK_HTTP_RESPONSE_MAX];
|
||||
char_t errorMessage[NETWORK_ERROR_MESSAGE_MAX];
|
||||
|
||||
thread_t thread;
|
||||
} networkhttppendingitem_t;
|
||||
|
||||
typedef struct {
|
||||
networkhttppendingitem_t requests[NETWORK_HTTP_PENDING_MAX];
|
||||
threadmutex_t resultsMutex;
|
||||
void *nothing;
|
||||
} networklinux_t;
|
||||
|
||||
/**
|
||||
@@ -71,48 +39,9 @@ errorret_t networkLinuxUpdate();
|
||||
*/
|
||||
bool_t networkLinuxIsConnected();
|
||||
|
||||
/**
|
||||
* No-op — Linux connection is managed by the OS. Calls onConnected immediately.
|
||||
*
|
||||
* @param onConnected Callback invoked immediately.
|
||||
* @param onFailed Unused.
|
||||
* @param user Passed to onConnected.
|
||||
*/
|
||||
void networkLinuxRequestConnection(
|
||||
void (*onConnected)(void *user),
|
||||
void (*onFailed)(errorret_t error, void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Disposes the network manager.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t networkLinuxDispose();
|
||||
|
||||
/**
|
||||
* Submits an asynchronous HTTP request. The callback will be invoked on the
|
||||
* main thread when next available.
|
||||
*
|
||||
* @param url URL to request.
|
||||
* @param method Method to use for the request.
|
||||
* @param bodyOrNull If POST or PUT, custom body string, can be NULL.
|
||||
* @param headers Array of key-value headers.
|
||||
* @param headerCount Count of headers, can be anything if headers is NULL.
|
||||
* @param user Callback pointer received to the callback.
|
||||
* @param callback The callback to invoke when the request completes.
|
||||
* @param errorCallback The callback to invoke if the request fails.
|
||||
* Note, this doesn't count Non-200 status codes, just
|
||||
* network errors.
|
||||
*/
|
||||
void networkLinuxHTTPRequest(
|
||||
const char_t *url,
|
||||
const networkhttprequestmethod_t method,
|
||||
const char_t *bodyOrNull,
|
||||
const networkhttpheader_t *headers,
|
||||
const uint32_t headerCount,
|
||||
void *user,
|
||||
networkhttpcallback_t callback,
|
||||
networkhttperrorcallback_t errorCallback
|
||||
);
|
||||
errorret_t networkLinuxDispose();
|
||||
Reference in New Issue
Block a user