AsyncTCP icon indicating copy to clipboard operation
AsyncTCP copied to clipboard

Async.tcp

Open omgdeauth opened this issue 1 year ago • 1 comments

/* Bibliothèque TCP asynchrone pour MCU Espressif Copyright (c) 2016 Hristo Gochkov. Tous les droits sont réservés. Ce fichier fait partie du noyau esp8266 pour l'environnement Arduino. Cette bibliothèque est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier selon les termes de la GNU Lesser General Public Licence telle que publiée par la Free Software Foundation ; Soit version 2.1 de la Licence, ou (à votre choix) toute version ultérieure. Cette bibliothèque est distribuée dans l'espoir qu'elle sera utile, mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de QUALITÉ MARCHANDE ou ADAPTATION À UN USAGE PARTICULIER. Voir le GNU Licence publique générale limitée pour plus de détails. Vous devriez avoir reçu une copie du GNU Lesser General Public Licence avec cette bibliothèque ; sinon, écrivez au Logiciel Libre Foundation, Inc., 51 Franklin St, Cinquième étage, Boston, MA 02110-1301 États-Unis / #ifndef ASYNCTCP_H_ #define ASYNCTCP_H_ #include "AdresseIP.h" #include "sdkconfig.h" #include "C" externe { #include "freertos/semphr.h" #include "lwip/pbuf.h" } // Si le noyau n'est pas défini, alors nous courons dans Arduino ou PIO #ifndef CONFIG_ASYNC_TCP_RUNNING_CORE #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 //tout cœur disponible #define CONFIG_ASYNC_TCP_USE_WDT 0 //si activé, ajoute entre 33us et 200us par événement #fin si classe AsyncClient ; #définir ASYNC_MAX_ACK_TIME 5000 #define ASYNC_WRITE_FLAG_COPY 0x01 // allouera un nouveau tampon pour contenir les données lors de l'envoi (sinon contiendra la référence aux données fournies) #define ASYNC_WRITE_FLAG_MORE 0x02 // n'enverra pas d'indicateur PSH, ce qui signifie qu'il devrait y avoir plus de données à envoyer avant que l'application ne réagisse. typedef std::function<void(void, AsyncClient*)> AcConnectHandler ; typedef std :: function<void(void*, AsyncClient*, size_t len, uint32_t time)> AcAckHandler ; typedef std :: function<void(void*, AsyncClient*, int8_t error)> AcErrorHandler ; typedef std :: function<void(void*, AsyncClient*, void data, size_t len)> AcDataHandler ; typedef std :: function<void(void, AsyncClient*, struct pbuf pb)> AcPacketHandler ; typedef std :: function<void(void, AsyncClient*, uint32_t time)> AcTimeoutHandler ; structure tcp_pcb ; structure ip_addr ; classe AsyncClient { Publique: AsyncClient(tcp_pcb* pcb = 0); ~AsyncClient(); AsyncClient & opérateur = (const AsyncClient & autre); AsyncClient & opérateur+=(const AsyncClient &other); bool operator==(const AsyncClient &other); opérateur booléen !=(const AsyncClient &autre) { retour !(ceci == autre); } bool connect(IPAddress IP, port uint16_t); bool connect(const char hôte, port uint16_t); void close(bool now = false); vide stop(); int8_t abandonner(); bool libre(); bool canSend();//ack n'est pas en attente size_t space();//espace disponible dans la fenêtre TCP size_t add(const char* data, size_t size, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY);//ajouter pour l'envoi bool send();//envoyer toutes les données ajoutées avec la méthode ci-dessus //écrire est égal à add()+send() size_t écriture (const char * données); size_t écrire (const char * données, size_t taille, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY); //uniquement lorsque canSend() == true état uint8_t(); bool connexion(); booléen connecté(); bool déconnecter(); booléen déconnecté(); bool freeable();//déconnecté ou déconnecté uint16_t getMss(); uint32_t getRxTimeout(); void setRxTimeout(uint32_t timeout);//aucun délai d'expiration des données RX pour la connexion en secondes uint32_t getAckTimeout(); void setAckTimeout(uint32_t timeout);//pas de délai d'attente ACK pour le dernier paquet envoyé en millisecondes void setNoDelay(bool nodelay); bool getNoDelay(); uint32_t getRemoteAddress(); uint16_t getRemotePort(); uint32_t getLocalAddress(); uint16_t getLocalPort(); //compatibilité adresse IP remoteIP(); uint16_t remotePort(); AdresseIPlocalIP(); uint16_t localPort(); void onConnect(AcConnectHandler cb, void* arg = 0); // en cas de connexion réussie void onDisconnect(AcConnectHandler cb, void* arg = 0); //débranché void onAck(AcAckHandler cb, void* arg = 0); //ack reçu void onError(AcErrorHandler cb, void* arg = 0); //échec de connexion ou erreur void onData(AcDataHandler cb, void* arg = 0); //données reçues (appelées si onPacket n'est pas utilisé) void onPacket(AcPacketHandler cb, void* arg = 0); //Donnée reçue void onTimeout(AcTimeoutHandler cb, void* arg = 0); // expiration du délai d'attente void onPoll(AcConnectHandler cb, void* arg = 0); // toutes les 125 ms lorsqu'il est connecté void ackPacket(struct pbuf * pb);//ack pbuf from onPacket size_t ack(size_t len); //Acquitter les données que vous n'avez pas acquittées en utilisant la méthode ci-dessous void ackLater(){ _ack_pcb = false ; } //n'accusera pas réception du paquet actuel. Appel depuis onData caractère const * errorToString (erreur int8_t); const char * stateToString(); //N'utilisez aucune des fonctions ci-dessous ! statique int8_t _s_poll(void arg, struct tcp_pcb tpcb); statique int8_t _s_recv(void arg, struct tcp_pcb tpcb, struct pbuf pb, int8_t err); statique int8_t _s_fin(void arg, struct tcp_pcb tpcb, int8_t err); statique int8_t _s_lwip_fin(void arg, struct tcp_pcb tpcb, int8_t err); vide statique _s_error(void arg, int8_t err); statique int8_t _s_sent(void arg, struct tcp_pcb tpcb, uint16_t len); statique int8_t _s_connected(void arg, void tpcb, int8_t err); static void _s_dns_found(const char name, struct ip_addr ipaddr, void arg); int8_t _recv(tcp_pcb pcb, pbuf pb, int8_t err); tcp_pcb * pcb(){ return _pcb ; } protégé: tcp_pcb _pcb ; int8_t _closed_slot ; AcConnectHandler _connect_cb ; void _connect_cb_arg ; AcConnectHandler _discard_cb ; void _discard_cb_arg ; AcAckHandler _sent_cb ; void _sent_cb_arg ; AcErrorHandler _error_cb ; void _error_cb_arg ; AcDataHandler_recv_cb ; void _recv_cb_arg ; AcPacketHandler _pb_cb ; vide _pb_cb_arg ; AcTimeoutHandler _timeout_cb ; void _timeout_cb_arg ; AcConnectHandler_poll_cb ; void _poll_cb_arg ; booléen_pcb_busy ; uint32_t _pcb_sent_at ; booléen_ack_pcb ; uint32_t _rx_ack_len ; uint32_t _rx_last_packet ; uint32_t _rx_since_timeout ; uint32_t _ack_timeout ; uint16_t _connect_port ; int8_t _close(); void _free_closed_slot(); void _allocate_closed_slot(); int8_t _connected(void pcb, int8_t err); void _error(int8_t err); int8_t _poll(tcp_pcb pcb); int8_t _sent(tcp_pcb* pcb, uint16_t len); int8_t _fin(tcp_pcb* pcb, int8_t err); int8_t _lwip_fin(tcp_pcb* pcb, int8_t err); void _dns_found(struct ip_addr ipaddr); Publique: AsyncClient précédent ; AsyncClient* suivant ; } ; classe AsyncServer { Publique: AsyncServer (adresse IP, port uint16_t); AsyncServer (port uint16_t); ~ServeurAsynchrone(); void onClient(AcConnectHandler cb, void* arg); void begin(); vide fin(); void setNoDelay(bool nodelay); bool getNoDelay(); état uint8_t(); //N'utilisez aucune des fonctions ci-dessous ! statique int8_t _s_accept(void arg, tcp_pcb newpcb, int8_t err); statique int8_t _s_accepted(void arg, AsyncClient client); protégé: uint16_t _port ; Adresse IP _addr ; booléen _noDelay ; tcp_pcb* _pcb ; AcConnectHandler _connect_cb ; void* _connect_cb_arg ; int8_t _accept(tcp_pcb* newpcb, int8_t err); int8_t accepted(client AsyncClient*); } ; #endif /* ASYNCTCP_H */

omgdeauth avatar Oct 13 '22 23:10 omgdeauth

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 21 '23 23:05 stale[bot]