file locking
This commit is contained in:
parent
0685fdf29a
commit
1f0f08f787
Binary file not shown.
@ -6,7 +6,8 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/file.h>
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
|
||||||
String shell_exec(String cmd)
|
String shell_exec(String cmd)
|
||||||
@ -91,33 +92,48 @@ bool file_exists(String path)
|
|||||||
|
|
||||||
String file_get_contents(String file_name)
|
String file_get_contents(String file_name)
|
||||||
{
|
{
|
||||||
try
|
/*std::ifstream ifs(file_name);
|
||||||
{
|
printf("stream file desc %i\n", ifs.filedesc());
|
||||||
std::ifstream ifs(file_name);
|
String content(
|
||||||
String content(
|
(std::istreambuf_iterator<char>(ifs) ),
|
||||||
(std::istreambuf_iterator<char>(ifs) ),
|
(std::istreambuf_iterator<char>() ) );*/
|
||||||
(std::istreambuf_iterator<char>() ) );
|
char buf[512];
|
||||||
return(content);
|
String content;
|
||||||
}
|
s32 fd = open(file_name.c_str(), O_RDONLY);
|
||||||
catch(std::exception e)
|
if(fd == -1)
|
||||||
{
|
{
|
||||||
|
printf("(!) Could not read %s\n", file_name.c_str());
|
||||||
return("");
|
return("");
|
||||||
}
|
}
|
||||||
|
flock(fd, LOCK_SH);
|
||||||
|
s64 bytes_read = 0;
|
||||||
|
//s64 size = lseek(fd, 0, SEEK_END);
|
||||||
|
//lseek(fd, 0, SEEK_SET);
|
||||||
|
//content.reserve(size+1);
|
||||||
|
|
||||||
|
while((bytes_read = read(fd, buf, 512)) > 0)
|
||||||
|
{
|
||||||
|
content.append(buf, bytes_read);
|
||||||
|
}
|
||||||
|
|
||||||
|
flock(fd, LOCK_UN);
|
||||||
|
close(fd);
|
||||||
|
return(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_put_contents(String file_name, String content)
|
bool file_put_contents(String file_name, String content)
|
||||||
{
|
{
|
||||||
try
|
s32 fd = open(file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
{
|
if(fd == -1)
|
||||||
std::ofstream out(file_name);
|
|
||||||
out << content;
|
|
||||||
out.close();
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
catch(std::exception e)
|
|
||||||
{
|
{
|
||||||
|
printf("(!) Could not write %s\n", file_name.c_str());
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
flock(fd, LOCK_EX);
|
||||||
|
write(fd, content.data(), content.length());
|
||||||
|
flock(fd, LOCK_UN);
|
||||||
|
close(fd);
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
String get_cwd()
|
String get_cwd()
|
||||||
|
|||||||
22
test/fileio.uce
Normal file
22
test/fileio.uce
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
RENDER()
|
||||||
|
{
|
||||||
|
DTree t;
|
||||||
|
|
||||||
|
<>
|
||||||
|
<link rel="stylesheet" href='style.css'></link>
|
||||||
|
<h1>
|
||||||
|
<a href="index.uce">UCE Test</a>:
|
||||||
|
FileI/O
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
File IO:
|
||||||
|
|
||||||
|
<pre style="white-space: pre-wrap"><?= file_get_contents("fileio.uce") ?></pre>
|
||||||
|
|
||||||
|
Params
|
||||||
|
<pre><?= var_dump(context->params) ?></pre>
|
||||||
|
</>
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ RENDER()
|
|||||||
<li><a href="json.uce">JSON</a></li>
|
<li><a href="json.uce">JSON</a></li>
|
||||||
<li><a href="memcached.uce">Memcached</a></li>
|
<li><a href="memcached.uce">Memcached</a></li>
|
||||||
<li><a href="mysql.uce">MySQL Connector</a></li>
|
<li><a href="mysql.uce">MySQL Connector</a></li>
|
||||||
|
<li><a href="fileio.uce">File I/O</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre><?
|
<pre><?
|
||||||
echo("Worker PID: "+std::to_string(my_pid)+"\n");
|
echo("Worker PID: "+std::to_string(my_pid)+"\n");
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
void show_form()
|
void show_form()
|
||||||
{
|
{
|
||||||
|
|
||||||
<form action="?" method="post" enctype="multipart/form-data">
|
<><form action="?" method="post" enctype="multipart/form-data">
|
||||||
<div>
|
<div>
|
||||||
<label>Some text:</label>
|
<label>Some text:</label>
|
||||||
<input type="text" name="fühld" value="<?= context->post["fühld"] ?>"/>
|
<input type="text" name="fühld" value="<?= context->post["fühld"] ?>"/>
|
||||||
@ -14,7 +14,7 @@ void show_form()
|
|||||||
<div>
|
<div>
|
||||||
<input type="submit" value="Submit Form"/>
|
<input type="submit" value="Submit Form"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form></>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
todo.txt
21
todo.txt
@ -1,6 +1,7 @@
|
|||||||
Library
|
Library
|
||||||
=================================
|
=================================
|
||||||
- sha1 / md5 / meow
|
- sha1 / md5 / meow
|
||||||
|
- fold StringList into DTree _OR_ make better StringList
|
||||||
|
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
@ -10,19 +11,27 @@ Bugs
|
|||||||
|
|
||||||
Framework
|
Framework
|
||||||
=================================
|
=================================
|
||||||
- Locks for file i/o
|
|
||||||
- Locks for compiler
|
|
||||||
- Check: File Upload
|
- Check: File Upload
|
||||||
- Proxy mode
|
- Proxy mode
|
||||||
- WebSockets
|
- WebSockets
|
||||||
- Persistent code / Cron / Tick?
|
- Resident code / Cron / Tick?
|
||||||
- Fork
|
- Automated Test Suite
|
||||||
- Multithreading
|
|
||||||
- Optionally store compiled units alongside source
|
|
||||||
|
Performance
|
||||||
|
=================================
|
||||||
|
- Arena Allocator
|
||||||
|
- Array implementation
|
||||||
|
|
||||||
|
|
||||||
Nice to Have
|
Nice to Have
|
||||||
=================================
|
=================================
|
||||||
- pseudorandom
|
- pseudorandom
|
||||||
- XML components
|
- XML components
|
||||||
|
- Optionally store compiled units alongside source
|
||||||
|
|
||||||
|
|
||||||
|
Finally
|
||||||
|
=================================
|
||||||
|
- DO WE DO OUR OWN LANGUAGE OR DO WE KEEP USING C?!?
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user