Compare commits
3 Commits
062edbac3c
...
3695a54e9a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3695a54e9a | ||
|
|
4dfdd76b05 | ||
|
|
8085397744 |
@@ -71,10 +71,7 @@ int TcpNet::server(int portno, const std::function<std::pair<bool, std::string>(
|
|||||||
shutdown = response.first;
|
shutdown = response.first;
|
||||||
std::string response_str = response.second;
|
std::string response_str = response.second;
|
||||||
|
|
||||||
auto response_len = response_str.size();
|
write_to_socket(newsockfd, response_str);
|
||||||
auto n = write(newsockfd, response_str.c_str(), response_len);
|
|
||||||
if (n < 0 || response_len != n)
|
|
||||||
error("ERROR writing to socket");
|
|
||||||
|
|
||||||
requests_processed++;
|
requests_processed++;
|
||||||
}
|
}
|
||||||
@@ -134,10 +131,20 @@ std::string TcpNet::client(const std::string &address, int portno, const std::st
|
|||||||
return response[0];
|
return response[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string TcpNet::read_from_socket(int sockfd) {
|
std::string TcpNet::read_from_socket(int sockfd) {
|
||||||
char buffer[TCPNET_BUFFER_SIZE];
|
char buffer[TCPNET_BUFFER_SIZE];
|
||||||
std::string request;
|
std::string request;
|
||||||
|
|
||||||
|
// read length header
|
||||||
|
unsigned long long bytesLen = 0;
|
||||||
|
if (USE_LENGTH_HEADER) {
|
||||||
|
long n = read(sockfd, &bytesLen, sizeof(bytesLen));
|
||||||
|
if (n != 0 && n != sizeof(bytesLen))
|
||||||
|
error("ERROR reading length header failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// read data
|
||||||
long n;
|
long n;
|
||||||
do {
|
do {
|
||||||
memset(buffer, 0, TCPNET_BUFFER_SIZE);
|
memset(buffer, 0, TCPNET_BUFFER_SIZE);
|
||||||
@@ -153,7 +160,7 @@ std::string TcpNet::read_from_socket(int sockfd) {
|
|||||||
|
|
||||||
std::string part{buffer};
|
std::string part{buffer};
|
||||||
request.append(part);
|
request.append(part);
|
||||||
} while (n == TCPNET_BUFFER_SIZE - 1); // TODO what if data exactly of this size
|
} while ((USE_LENGTH_HEADER && n < bytesLen) || n == TCPNET_BUFFER_SIZE - 1); // TODO what if data exactly of this size
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
@@ -162,6 +169,16 @@ void TcpNet::write_to_socket(int sockfd, const std::string &str) {
|
|||||||
const char *buffer = str.c_str();
|
const char *buffer = str.c_str();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
|
// write length header
|
||||||
|
unsigned long long bytesLen = str.length();
|
||||||
|
if (USE_LENGTH_HEADER) {
|
||||||
|
n = write(sockfd, &bytesLen, (int) sizeof(bytesLen));
|
||||||
|
if (n < 0)
|
||||||
|
error("ERROR writing size number to socket");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write data
|
||||||
do {
|
do {
|
||||||
n = write(sockfd, buffer + pos, (int) (str.length() - pos));
|
n = write(sockfd, buffer + pos, (int) (str.length() - pos));
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public:
|
|||||||
[[nodiscard]] std::vector<std::string> client(const std::string &address, int portno, const std::vector<std::string> &requests) const;
|
[[nodiscard]] std::vector<std::string> client(const std::string &address, int portno, const std::vector<std::string> &requests) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const bool USE_LENGTH_HEADER = true;
|
||||||
static std::string read_from_socket(int sockfd) ;
|
static std::string read_from_socket(int sockfd) ;
|
||||||
static void write_to_socket(int sockfd, const std::string &str) ;
|
static void write_to_socket(int sockfd, const std::string &str) ;
|
||||||
};
|
};
|
||||||
|
|||||||
21
debug.lsp
21
debug.lsp
@@ -1,4 +1,19 @@
|
|||||||
; (system-cmd-fork "ml" "-c" "(print 123) (sleep 1) (print \"aaa\")")
|
(thread-create
|
||||||
|
(tcp-server 7777 (lambda (str) (list #f (+ "(print \"" (string-upcase str) "\")"))))
|
||||||
|
)
|
||||||
|
|
||||||
(print (reduce (lambda (acc e) (+ acc (string (+ "<th>" e "</th>")))) "" '("h1" "h2" "h3"))
|
(thread-sleep 1)
|
||||||
)
|
|
||||||
|
(thread-create
|
||||||
|
(def code (tcp-client "127.0.0.1" 7777 ("abcd" "xyz")))
|
||||||
|
(for c code
|
||||||
|
(print "executing code:" c)
|
||||||
|
(eval (parse c))
|
||||||
|
)
|
||||||
|
|
||||||
|
(def code (tcp-client "127.0.0.1" 7777 "abcd"))
|
||||||
|
(print "executing code:" code)
|
||||||
|
(eval (parse code))
|
||||||
|
)
|
||||||
|
(threads-join)
|
||||||
|
(print "ok")
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ RUN cd /mlisp \
|
|||||||
# Create image and copy compiled installation into it
|
# Create image and copy compiled installation into it
|
||||||
FROM alpine:3.15.4
|
FROM alpine:3.15.4
|
||||||
|
|
||||||
RUN apk add openssl libstdc++
|
RUN apk add --no-cache openssl libstdc++
|
||||||
|
|
||||||
CMD mkdir -p /usr/local/var/mlisp/
|
CMD mkdir -p /usr/local/var/mlisp/
|
||||||
COPY --from=builder /mlisp/stdlib/*.lsp /usr/local/var/mlisp/
|
COPY --from=builder /mlisp/stdlib/*.lsp /usr/local/var/mlisp/
|
||||||
|
|||||||
1
tests/cmd_fork.lsp
Normal file
1
tests/cmd_fork.lsp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(system-cmd-fork "ml" "-c" "(print 123) (sleep 1) (print \"aaa\")")
|
||||||
19
tests/test_tcp.lsp
Normal file
19
tests/test_tcp.lsp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
(thread-create
|
||||||
|
(tcp-server 7777 (lambda (str) (list #f (+ "(print \"" (string-upcase str) "\")"))))
|
||||||
|
)
|
||||||
|
|
||||||
|
(thread-sleep 1)
|
||||||
|
|
||||||
|
(thread-create
|
||||||
|
(def code (tcp-client "127.0.0.1" 7777 ("abcd" "xyz")))
|
||||||
|
(for c code
|
||||||
|
(print "executing code:" c)
|
||||||
|
(eval (parse c))
|
||||||
|
)
|
||||||
|
|
||||||
|
(def code (tcp-client "127.0.0.1" 7777 "abcd"))
|
||||||
|
(print "executing code:" code)
|
||||||
|
(eval (parse code))
|
||||||
|
)
|
||||||
|
(threads-join)
|
||||||
|
(print "ok")
|
||||||
20
wip.lsp
20
wip.lsp
@@ -3,26 +3,6 @@
|
|||||||
(print (filter (lambda (eval e) (print e)) l))
|
(print (filter (lambda (eval e) (print e)) l))
|
||||||
|
|
||||||
|
|
||||||
(thread-create
|
|
||||||
(tcp-server 7777 (lambda (str) (list #f (+ "(print \"" (string-upcase str) "\")"))))
|
|
||||||
)
|
|
||||||
|
|
||||||
(thread-sleep 1)
|
|
||||||
|
|
||||||
(thread-create
|
|
||||||
(def code (tcp-client "127.0.0.1" 7777 ("abcd" "xyz")))
|
|
||||||
(for c code
|
|
||||||
(print "executing code:" c)
|
|
||||||
(eval (parse c))
|
|
||||||
)
|
|
||||||
|
|
||||||
(def code (tcp-client "127.0.0.1" 7777 "abcd"))
|
|
||||||
(print "executing code:" code)
|
|
||||||
(eval (parse code))
|
|
||||||
)
|
|
||||||
(threads-join)
|
|
||||||
(print "ok")
|
|
||||||
|
|
||||||
|
|
||||||
;; (usql "create table sf1 (symbol varchar(8), dimension varchar(3), calendar_date date, date_key date, report_period date, last_updated date, accoci float, assets float, assetsavg float, assetsc float, assetsnc float, assetturnover float, bvps float, capex float, cashneq float, cashnequsd float, cor float, consolinc float, currentratio float, de float, debt float, debtc float, debtnc float, debtusd float, deferredrev float, depamor float, deposits float, divyield float, dps float, ebit float, ebitda float, ebitdamargin float, ebitdausd float, ebitusd float, ebt float, eps float, epsdil float, epsusd float, equity float, equityavg float, equityusd float, ev float, evebit float, evebitda float, fcf float, fcfps float, fxusd float, gp float, grossmargin float, intangibles float, intexp float, invcap float, invcapavg float, inventory float, investments float, investmentsc float, investmentsnc float, liabilities float, liabilitiesc float, liabilitiesnc float, marketcap float, ncf float, ncfbus float, ncfcommon float, ncfdebt float, ncfdiv float, ncff float, ncfi float, ncfinv float, ncfo float, ncfx float, netinc float, netinccmn float, netinccmnusd float, netincdis float, netincnci float, netmargin float, opex float, opinc float, payables float, payoutratio float, pb float, pe float, pe1 float, ppnenet float, prefdivis float, price float, ps float, ps1 float, receivables float, retearn float, revenue float, revenueusd float, rnd float, roa float, roe float, roic float, ros float, sbcomp float, sgna float, sharefactor float, sharesbas float, shareswa float, shareswadil float, sps float, tangibles float, taxassets float, taxexp float, taxliabilities float, tbvps float, workingcapital float)")
|
;; (usql "create table sf1 (symbol varchar(8), dimension varchar(3), calendar_date date, date_key date, report_period date, last_updated date, accoci float, assets float, assetsavg float, assetsc float, assetsnc float, assetturnover float, bvps float, capex float, cashneq float, cashnequsd float, cor float, consolinc float, currentratio float, de float, debt float, debtc float, debtnc float, debtusd float, deferredrev float, depamor float, deposits float, divyield float, dps float, ebit float, ebitda float, ebitdamargin float, ebitdausd float, ebitusd float, ebt float, eps float, epsdil float, epsusd float, equity float, equityavg float, equityusd float, ev float, evebit float, evebitda float, fcf float, fcfps float, fxusd float, gp float, grossmargin float, intangibles float, intexp float, invcap float, invcapavg float, inventory float, investments float, investmentsc float, investmentsnc float, liabilities float, liabilitiesc float, liabilitiesnc float, marketcap float, ncf float, ncfbus float, ncfcommon float, ncfdebt float, ncfdiv float, ncff float, ncfi float, ncfinv float, ncfo float, ncfx float, netinc float, netinccmn float, netinccmnusd float, netincdis float, netincnci float, netmargin float, opex float, opinc float, payables float, payoutratio float, pb float, pe float, pe1 float, ppnenet float, prefdivis float, price float, ps float, ps1 float, receivables float, retearn float, revenue float, revenueusd float, rnd float, roa float, roe float, roic float, ros float, sbcomp float, sgna float, sharefactor float, sharesbas float, shareswa float, shareswadil float, sps float, tangibles float, taxassets float, taxexp float, taxliabilities float, tbvps float, workingcapital float)")
|
||||||
;; (usql "set 'DATE_FORMAT' = '%Y-%m-%d'")
|
;; (usql "set 'DATE_FORMAT' = '%Y-%m-%d'")
|
||||||
|
|||||||
Reference in New Issue
Block a user