Comments (3)
I victory my problem
And it's result code
import socket
import sys
import os
class epoll_data:
ptr: Ptr[byte]
fd: i32
u32: u32
u64: u64
def __repr__(self) -> str:
return f'[ptr={self.ptr},fd={self.fd},u32={self.u32},u64={self.u64}]'
@tuple
class epoll_event:
events: u32
data: epoll_data
def __new__(_events: u32, _data: epoll_data):
return epoll_event(_events, _data)
def __repr__(self) -> str:
return f'[events={self.events},data={self.data}]'
from C import epoll_create(i32) -> i32
from C import epoll_ctl(i32, i32, i32, Ptr[byte]) -> i32
from C import epoll_wait(i32, Ptr[byte], i32, i32) -> i32
EPOLLIN = u32(0x001)
EPOLLET = u32(int(1u) << 31)
EPOLL_CTL_ADD = i32(1)
EPOLL_CTL_DEL = i32(2)
EPOLL_CTL_MOD = i32(3)
host = '127.0.0.1' # Symbolic name meaning all available interfaces
port = 8001 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setnonblocking(s.__sock);
s.bind((host, port))
s.listen(1)
print(host, port)
wait_events = __array__[epoll_event](256)
ev = epoll_event(EPOLLIN)
ev.data.fd = s.__sock
print(ev)
epollfd = epoll_create(i32(256))
epoll_ctl(epollfd, EPOLL_CTL_ADD, s.__sock, __ptr__(ev).as_byte())
while True:
new_events = epoll_wait(epollfd, wait_events.ptr.as_byte(), i32(256), i32(-1))
print(int(new_events))
if int(new_events) == -1:
break
for i in range(int(new_events)):
print(i)
event = wait_events[i]
print(f'Event: {event}')
if event.data.fd == s.__sock:
sock_conn, sock_addr = s.accept()
socket.setnonblocking(sock_conn.__sock);
print('Connected by: ', sock_addr)
ev2 = epoll_event(EPOLLIN | EPOLLET)
ev2.data.fd = sock_conn.__sock
epoll_ctl(epollfd, EPOLL_CTL_ADD, sock_conn.__sock, __ptr__(ev2).as_byte())
else:
newsockfd = event.data.fd
data = socket.recv(newsockfd, 1024)
print("Client says: " + data)
if not data:
break
else:
#shutdown(newsockfd, SHUT_RDWR)
socket.sendall(newsockfd, "HTTP/1.1 200 OK\nServer: Z-Server\nContent-type: text/html\n\n<html><body>Z-Server</body></html>")
epoll_ctl(epollfd, EPOLL_CTL_DEL, newsockfd, Ptr[byte](0))
socket.close(newsockfd)
But when run and build sometime not working and
in it place code
event = wait_events[i]
print(f'Event: {event}')
Get sometimes Segmentation Fault .... Very very strange
Please help ! Codon is the Super !
from codon.
- and when run with
codon run -release http_server.codon
All times Segmentation Fault
event = wait_events[i]
print(f'Event: {event}')
from codon.
This is definitely a bug—thank you for the report!
Also, you should initialize ptr
here:
def __init__(self):
pass
Otherwise it will get garbage value and might cause segfault.
from codon.
Related Issues (20)
- Unbuffered output HOT 1
- Inheritance between 3 classes gives an infer.cpp error HOT 1
- Error: no member named 'ExecutorSymbolDef' in namespace 'llvm::orc'
- how to integration c++ class
- bench/set_partition c++ error: no matching function for call to 'partition_filtered' HOT 2
- Build process for the jupyter plugin stops midway (MacOS)
- TypeVar and ParamSpec type expression fail HOT 5
- What is the difference between the support for reflection in Codon and Python? HOT 1
- using protobuf case HOT 5
- CURSED HOT 2
- 【Codon】With repeated processing, memory consumption increases, Killed is displayed, and processing stops. HOT 2
- Cannot set the bits of UInt data with __setitem__.
- Codon slower than PyPy, can't find out why HOT 1
- Inheritance breaks Optional
- Interop with Python breaks CTRL+C HOT 1
- Generated LLVM code can't be used by lli
- Error:Tuple from_py overload match problem
- String concatenation in a loop slow compared to Python HOT 3
- codon for android HOT 1
- Bad Performance HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codon.