-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
socket library example inside Lib/socket/lib.bic
This is just an idea for a module system for bichara. Anyway, it is starting to look a lot more like a 'professional' programming language
- Loading branch information
1 parent
03bae55
commit b6ebb58
Showing
17 changed files
with
317 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
BUILD_PATH=../ | ||
|
||
gcc -c -Wall -Werror -fpic sock.c | ||
gcc -shared -o $BUILD_PATH/libbich.so sock.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import socket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Creates a POSIX environment socket and returns a file | ||
// descriptor for that socket. | ||
// | ||
// Arguments: | ||
// port: Port to bind the socket to. | ||
def extern __BICH_POSIX__create_socket(port: integer) -> integer; | ||
|
||
// Listens for incoming connections on the specified socket file descriptor. | ||
// | ||
// Arguments: | ||
// fd: The file descriptor for the socket. | ||
// backlog: The maximum length of the queue for pending connections. | ||
def extern __BICH_POSIX__listen_socket(fd: integer, backlog: integer) -> void; | ||
|
||
// Accepts an incoming connection on the specified socket file descriptor. | ||
// | ||
// Arguments: | ||
// fd: The file descriptor for the socket. | ||
// | ||
// Returns: A new file descriptor for the accepted connection. | ||
def extern __BICH_POSIX__accept_socket_conn(fd: integer) -> integer; | ||
|
||
// Writes a message to the specified socket file descriptor. | ||
// | ||
// Arguments: | ||
// fd: The file descriptor for the socket. | ||
// msg: The message to be sent over the socket. | ||
// size: The size of the message in bytes. | ||
def extern __BICH_POSIX__write_socket(fd: integer, msg: str, size: integer) -> void; | ||
|
||
// Closes the specified socket file descriptor. | ||
// | ||
// Arguments: | ||
// fd: The file descriptor for the socket to be closed. | ||
def extern __BICH_POSIX__close_socket(fd: integer) -> void; | ||
|
||
// Create a socket | ||
def create_socket(port: integer) -> integer { | ||
if (port < 0) { | ||
return 0; | ||
} | ||
if (port > 65535) { | ||
return 0; | ||
} | ||
return __BICH_POSIX__create_socket(port); | ||
} | ||
|
||
def listen_socket(fd: integer, backlog: integer) -> void { | ||
if (fd < 0) { | ||
return; | ||
} | ||
__BICH_POSIX__listen_socket(fd); | ||
} | ||
|
||
def accept_socket(fd: integer) -> integer { | ||
if (fd < 0) { | ||
return 0; | ||
} | ||
return __BICH_POSIX__accept_socket_conn(fd); | ||
} | ||
|
||
def write_socket(fd: integer, msg: str, size: integer) -> void { | ||
if (fd < 0) { | ||
return; | ||
} | ||
__BICH_POSIX__write_socket(fd, msg, size); | ||
} | ||
|
||
def close_socket(fd: integer) -> void { | ||
__BICH_POSIX__close_socket(fd); | ||
} | ||
|
||
def main() -> void { | ||
let fd: integer = create_socket(8080); | ||
listen_socket(fd, 3); | ||
|
||
loop { | ||
let new_fd: integer = accept_socket(fd); | ||
let http_response = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 25\r\n\r\n<b>Hello from Bichara</b>"; | ||
write_socket(new_fd, http_response, 90); | ||
close_socket(new_fd); | ||
} | ||
close_socket(fd); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
BICH_STD_LIB_PATH=. | ||
|
||
RUST_BACKTRACE=1 cargo run 1> main.S | ||
gcc -o out main.S -L$BICH_STD_LIB_PATH -lbich | ||
|
||
export DYLD_LIBRARY_PATH=./:$DYLD_LIBRARY_PATH | ||
./out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.