Sync betaflight to Gitea
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2016 rxi
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||

|
||||
|
||||
## Overview
|
||||
Dyad.c is an asynchronous networking library which aims to be lightweight,
|
||||
portable and easy to use. It can be used both to create small standalone
|
||||
servers and to provide network support to existing projects.
|
||||
|
||||
## Getting started
|
||||
The [dyad.c](src/dyad.c?raw=1) and [dyad.h](src/dyad.h?raw=1) files can be
|
||||
dropped into an existing project; if you're using Windows you will also have to
|
||||
link to `ws2_32`.
|
||||
|
||||
An overview of the API can be found at [doc/api.md](doc/api.md).
|
||||
|
||||
Usage examples can be found at [example/](example/).
|
||||
|
||||
## Server example
|
||||
A simple server which listens on port 8000 and echoes whatever is sent to it:
|
||||
```c
|
||||
#include <stdlib.h>
|
||||
#include "dyad.h"
|
||||
|
||||
static void onData(dyad_Event *e) {
|
||||
dyad_write(e->stream, e->data, e->size);
|
||||
}
|
||||
|
||||
static void onAccept(dyad_Event *e) {
|
||||
dyad_addListener(e->remote, DYAD_EVENT_DATA, onData, NULL);
|
||||
dyad_writef(e->remote, "Echo server\r\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
dyad_init();
|
||||
|
||||
dyad_Stream *serv = dyad_newStream();
|
||||
dyad_addListener(serv, DYAD_EVENT_ACCEPT, onAccept, NULL);
|
||||
dyad_listen(serv, 8000);
|
||||
|
||||
while (dyad_getStreamCount() > 0) {
|
||||
dyad_update();
|
||||
}
|
||||
|
||||
dyad_shutdown();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## Client example
|
||||
A simple example program which connects to a
|
||||
[daytime](http://en.wikipedia.org/wiki/Daytime_Protocol) server and prints the
|
||||
response:
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include "dyad.h"
|
||||
|
||||
static void onConnect(dyad_Event *e) {
|
||||
printf("connected: %s\n", e->msg);
|
||||
}
|
||||
|
||||
static void onData(dyad_Event *e) {
|
||||
printf("%s", e->data);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
dyad_init();
|
||||
|
||||
dyad_Stream *s = dyad_newStream();
|
||||
dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);
|
||||
dyad_addListener(s, DYAD_EVENT_DATA, onData, NULL);
|
||||
dyad_connect(s, "time-nw.nist.gov", 13);
|
||||
|
||||
while (dyad_getStreamCount() > 0) {
|
||||
dyad_update();
|
||||
}
|
||||
|
||||
dyad_shutdown();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
This library is free software; you can redistribute it and/or modify it under
|
||||
the terms of the MIT license. See [LICENSE](LICENSE) for details.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2016 rxi
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef DYAD_H
|
||||
#define DYAD_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h> /* For SOCKET */
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if _WIN32
|
||||
typedef SOCKET dyad_Socket;
|
||||
#else
|
||||
typedef int dyad_Socket;
|
||||
#endif
|
||||
|
||||
struct dyad_Stream;
|
||||
typedef struct dyad_Stream dyad_Stream;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
void *udata;
|
||||
dyad_Stream *stream;
|
||||
dyad_Stream *remote;
|
||||
const char *msg;
|
||||
char *data;
|
||||
int size;
|
||||
} dyad_Event;
|
||||
|
||||
typedef void (*dyad_Callback)(dyad_Event*);
|
||||
typedef void (*dyad_PanicCallback)(const char*);
|
||||
|
||||
enum {
|
||||
DYAD_EVENT_NULL,
|
||||
DYAD_EVENT_DESTROY,
|
||||
DYAD_EVENT_ACCEPT,
|
||||
DYAD_EVENT_LISTEN,
|
||||
DYAD_EVENT_CONNECT,
|
||||
DYAD_EVENT_CLOSE,
|
||||
DYAD_EVENT_READY,
|
||||
DYAD_EVENT_DATA,
|
||||
DYAD_EVENT_LINE,
|
||||
DYAD_EVENT_ERROR,
|
||||
DYAD_EVENT_TIMEOUT,
|
||||
DYAD_EVENT_TICK
|
||||
};
|
||||
|
||||
enum {
|
||||
DYAD_STATE_CLOSED,
|
||||
DYAD_STATE_CLOSING,
|
||||
DYAD_STATE_CONNECTING,
|
||||
DYAD_STATE_CONNECTED,
|
||||
DYAD_STATE_LISTENING
|
||||
};
|
||||
|
||||
|
||||
void dyad_init(void);
|
||||
void dyad_update(void);
|
||||
void dyad_shutdown(void);
|
||||
const char *dyad_getVersion(void);
|
||||
double dyad_getTime(void);
|
||||
int dyad_getStreamCount(void);
|
||||
void dyad_setTickInterval(double seconds);
|
||||
void dyad_setUpdateTimeout(double seconds);
|
||||
dyad_PanicCallback dyad_atPanic(dyad_PanicCallback func);
|
||||
|
||||
dyad_Stream *dyad_newStream(void);
|
||||
int dyad_listen(dyad_Stream *stream, int port);
|
||||
int dyad_listenEx(dyad_Stream *stream, const char *host, int port,
|
||||
int backlog);
|
||||
int dyad_connect(dyad_Stream *stream, const char *host, int port);
|
||||
void dyad_addListener(dyad_Stream *stream, int event,
|
||||
dyad_Callback callback, void *udata);
|
||||
void dyad_removeListener(dyad_Stream *stream, int event,
|
||||
dyad_Callback callback, void *udata);
|
||||
void dyad_removeAllListeners(dyad_Stream *stream, int event);
|
||||
void dyad_end(dyad_Stream *stream);
|
||||
void dyad_close(dyad_Stream *stream);
|
||||
void dyad_write(dyad_Stream *stream, const void *data, int size);
|
||||
void dyad_vwritef(dyad_Stream *stream, const char *fmt, va_list args);
|
||||
void dyad_writef(dyad_Stream *stream, const char *fmt, ...);
|
||||
void dyad_setTimeout(dyad_Stream *stream, double seconds);
|
||||
void dyad_setNoDelay(dyad_Stream *stream, int opt);
|
||||
int dyad_getState(dyad_Stream *stream);
|
||||
const char *dyad_getAddress(dyad_Stream *stream);
|
||||
int dyad_getPort(dyad_Stream *stream);
|
||||
int dyad_getBytesSent(dyad_Stream *stream);
|
||||
int dyad_getBytesReceived(dyad_Stream *stream);
|
||||
dyad_Socket dyad_getSocket(dyad_Stream *stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user