diff --git a/.gitignore b/.gitignore index db25df0..2b9712b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.uaem *.Bak +dist/ +build/ +aminet/ diff --git a/LICENSE b/LICENSE index a4e9dc9..37fa1de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT No Attribution -Copyright +Copyright 2023 John Bintz 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 diff --git a/README.md b/README.md index cdd39a3..82402b8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # amos-pro-bsdsocket-extension -Want to get online with your AMOS program? Now you can in (some) style! +Want to get online with your AMOS program? Now you can in style! This extension provides a wrapper around the BSD Socket library provided by your Internet stack. There's some attempt to roll up some @@ -151,16 +151,33 @@ This project uses semantic versioning. Copyright 2023 John Bintz. Licensed under the MIT License. If you use this in your project, and you really want to, -throw a link to theindustriousrabbit.com somewhere. +throw a link to theindustriousrabbit.com somewhere! You can +also find a donate link on +[the About section on The Industrious Rabbit](https://theindustriousrabbit.com/about). ## Feedback? Bug reports? Go to the [About section on The Industrious Rabbit](https://theindustriousrabbit.com/about) to contact me. +## Changelog + +### 0.7.0 (2023-02-20) + +* Current development release + ## Development ### Environment * Clone the [AMOS Professional source code](https://github.com/AOZ-Studio/AMOS-Professional-Official) -* Copy the contents of +* Copy the contents of `src` into the `extensions` folder +* Run `absdsocket` + +### Releasing + +#### Ubuntu/Debian + +* Install `jlha-utils` and a modern enough Java to run it +* Install Ruby +* Run `bin/release` diff --git a/aminet.readme.erb b/aminet.readme.erb new file mode 100644 index 0000000..a21437d --- /dev/null +++ b/aminet.readme.erb @@ -0,0 +1,17 @@ +Short: Use bsdsocket.library in AMOS Pro +Uploader: aminet@theindustriousrabbit.com (John Bintz) +Author: John Bintz +Type: dev/amos +Version: <%= version %> +Architecture: m68k-amigaos + +Want to get online with your AMOS program? Now you can in style! + +This extension provides a wrapper around the BSD Socket library +provided by your Internet stack. There's some attempt to roll up some +of the low-level functionality into something more usable by AMOS. + +More details provided in README.md in the archive file, and in the +source code repository at: +https://code.hackerbun.dev/TheIndustriousRabbit/amos-pro-bsdsocket-extension + diff --git a/bin/rebuild_raw_source b/bin/rebuild_raw_source new file mode 100755 index 0000000..2a1b19b --- /dev/null +++ b/bin/rebuild_raw_source @@ -0,0 +1,6 @@ +#!/bin/bash + +for i in examples/*.amos; do + echo "$i" + ~/Projects/amostools/listamos -e AMOSPro_BSDSocket.Lib "${i}" > "${i%.amos}.basic" 2>/dev/null +done diff --git a/bin/release b/bin/release new file mode 100755 index 0000000..dd9dd06 --- /dev/null +++ b/bin/release @@ -0,0 +1,81 @@ +#!/usr/bin/env ruby + +require 'fileutils' +require 'open3' +require 'erb' + +source = File.read('src/BSDSocket.s') + +aminet_template = ERB.new(File.read("aminet.readme.erb")) + +capture_version = false +version = nil + +source.lines.each do |line| + if capture_version + version = line[/dc\.b "([^"]+)"/,1] + + break + end + + if line[/^Version.*MACRO/] + # the version is on the next line + capture_version = true + end +end + +FileUtils.mkdir_p 'dist' + +build_base = 'build' +project_name = 'BSDSocket-Extension' + +build_dir = File.join(build_base, project_name) +FileUtils.rm_rf build_dir +FileUtils.mkdir_p build_dir +FileUtils.mkdir_p 'aminet' + +hackerbun_target = File.expand_path("dist/AMOSPro_BSDSocket_#{version}.lha") + +[ + "AMOSPro_BSDSocket.Lib", + "README.md", + "API.md", + "LICENSE", +].each do |file| + target = "#{build_dir}/#{file}" + FileUtils.mkdir_p File.dirname(target) + FileUtils.cp file, target +end + +[ + "src", + "examples" +].each do |dir| + FileUtils.cp_r dir, "#{build_dir}/#{dir}" +end + +Dir["icons/**/*.info"].each do |info| + target = info.gsub("icons/", build_base + "/") + FileUtils.mkdir_p File.dirname(target) + FileUtils.cp info, target +end + +Dir.chdir build_base do + Open3.popen2e( + "jlha", "c", hackerbun_target, + *(Dir["*"])) do |stdin, stdout_and_stderr, wait_thr| + + Thread.new do + stdout_and_stderr.each { |l| puts l } + end + + stdin.close + + wait_thr.value + end +end + +FileUtils.cp hackerbun_target, "aminet/BSDSocket-Extension.lha" +File.open("aminet/BSDSocket-Extension.readme", "w") do |fh| + fh.puts aminet_template.result(binding) +end diff --git a/HTTP Client Example.amos b/examples/HTTP Client Example.amos similarity index 100% rename from HTTP Client Example.amos rename to examples/HTTP Client Example.amos diff --git a/examples/HTTP Client Example.basic b/examples/HTTP Client Example.basic new file mode 100644 index 0000000..f29e981 --- /dev/null +++ b/examples/HTTP Client Example.basic @@ -0,0 +1,93 @@ +' This code shows how to make a non-blocking request with +' timeout to a remote HTTP server to retrieve a webpage +' and print it on the screen. +' +' This requires the BSD Socket Extension installed in Extension +' Slot 18. +' +' Copyright 2023 John Bintz +' Visit theindustriousrabbit.com for more info +' Licensed under the MIT License + +LIB=Socket Library Open + +If LIB<=0 + Print "Unable to open bsdsocket.library!" + End +End If + +SOCKET=Socket Create Inet Socket + +' A lot of functions return debugging info. Assign that to +' some useless variable, unless you're trying to figure out +' an issue with the extension. +_=Socket Set Nonblocking(SOCKET,True) + +HOST$="aminet.net" +Print "Trying to connect to "+HOST$ +IP$=Dns Get Address By Name$(HOST$) + +' When nonblocking sockets start to connect, they may or +' may not finish their connection before the function +' returns. If the socket doesn't connect, we have to wait +' for it to do so. +ALREADY_CONNECTED=Socket Connect(SOCKET To IP$,80) + +Reserve As Work 30,1024 + +' Due to how AMOS takes over Ctrl-C handing, there's no way +' for the bsdsocket code to use Exec's Ctrl-C handling. +' This means we need to poll for network activity. +' However, the async functions will immediately return +' if they get appropriate data before the timeout ends. +' This is somewhat more CPU efficient. +For I=1 To 100 + If ALREADY_CONNECTED=-1 + ' We can check a socket for writing if it's currently + ' attempting to connect. Once it connects, we can stop + ' checking for that status -- we're ready to communicate + ' with the remote server. + RESULT=Socket Wait Async Writing(SOCKET,100) + + If RESULT>0 + ALREADY_CONNECTED=0 + End If + End If + + If ALREADY_CONNECTED=0 + Print "Connected to "+HOST$ + + HTTPGET$="GET / HTTP/1.0"+Chr$(10)+"Host: amiga"+Chr$(10)+Chr$(10) + Print "Making HTTP request to "+HOST$ + _=Socket Send(SOCKET,Varptr(HTTPGET$),Len(HTTPGET$)) + + For J=1 To 100 + RESULT=Socket Wait Async Reading(SOCKET,50) + + If RESULT>0 + Print "Receiving data" + ' You can receive either to a block of memory... + ' + 'OUT=Socket Recv(SOCKET To Start(30),1024) + 'For K=0 To OUT-1 + ' _DATA$=_DATA$+Chr$(Peek(Start(30)+K)) + 'Next K + ' + ' ...or to a string... + _DATA$=Socket Recv$(SOCKET,1024) + + Print _DATA$ + ' If the amount read is less than the length of data, + ' assume we're done. This is fine for HTTP. + If Len(_DATA$)<1024 + Exit 2 + End If + End If + Next J + Exit + End If +Next I + +Socket Library Close + + diff --git a/examples/HTTP Server Example.amos b/examples/HTTP Server Example.amos new file mode 100644 index 0000000..e8e5f16 Binary files /dev/null and b/examples/HTTP Server Example.amos differ diff --git a/examples/HTTP Server Example.basic b/examples/HTTP Server Example.basic new file mode 100644 index 0000000..956d97a --- /dev/null +++ b/examples/HTTP Server Example.basic @@ -0,0 +1,56 @@ +' This is example code for opening a port on your machine, +' waiting for a client to connect, then printing out the +' first 1024 bytes the server receives from the client. +' +' Copyright 2023 John Bintz +' Licensed under the MIT License +' Visit theindustriousrabbit.com for more information + +If Socket Library Open<=0 + End +End If + +SOCKET=Socket Create Inet Socket + +' Ensure our socket does not block, and that we can reuse +' the address we bind to right away if our server is closed. +_=Socket Set Nonblocking(SOCKET,True) +_=Socket Reuse Addr(SOCKET) + +' You can bind your socket to any interface on the machine. +' You'd have to get that list of interfaces yourself. +' Using "INADDR_ANY" is the equivalent of binding to 0.0.0.0. +RESULT=Socket Bind(SOCKET To "INADDR_ANY",8000) + +_=Socket Listen(SOCKET) +Print "Listening on port 8000" + +For I=1 To 100 + ' Here. we're testing our non-blocking async socket for + ' reading. If the socket has been connected to, this request + ' will return a value greater than 0. Otherwise, it will + ' wait for a half second, then return 0. + RESULT=Socket Wait Async Reading(SOCKET,500) + + If RESULT>0 + ' Accept the connection so we can receive data from it. + _REMOTE_SOCKET=Socket Accept(SOCKET) + + ' Print out the remote IP address and port. + Print Socket Inet Ntoa$(Socket Get Host(_REMOTE_SOCKET)) + Print Socket Get Port(_REMOTE_SOCKET) + + ' Receive the first 1024 or fewer bytes of data from the + ' client and print them out. + Print Socket Recv$(_REMOTE_SOCKET,1024) + + ' If we exit now, the connection will stay open. Closing the + ' library or restarting the program will close all open + ' connections. + Exit + End If + Wait Vbl +Next I + +Socket Library Close + diff --git a/http get v3.amos b/http get v3.amos deleted file mode 100644 index 0265493..0000000 Binary files a/http get v3.amos and /dev/null differ diff --git a/icons.info b/icons.info new file mode 100644 index 0000000..2470fed Binary files /dev/null and b/icons.info differ diff --git a/icons/BSDSocket-Extension.info b/icons/BSDSocket-Extension.info new file mode 100644 index 0000000..95a7a0d Binary files /dev/null and b/icons/BSDSocket-Extension.info differ diff --git a/icons/BSDSocket-Extension/AMOSPro_BSDSocket.Lib.info b/icons/BSDSocket-Extension/AMOSPro_BSDSocket.Lib.info new file mode 100644 index 0000000..d31099b Binary files /dev/null and b/icons/BSDSocket-Extension/AMOSPro_BSDSocket.Lib.info differ diff --git a/icons/BSDSocket-Extension/API.md.info b/icons/BSDSocket-Extension/API.md.info new file mode 100644 index 0000000..2895d19 Binary files /dev/null and b/icons/BSDSocket-Extension/API.md.info differ diff --git a/icons/BSDSocket-Extension/LICENSE.info b/icons/BSDSocket-Extension/LICENSE.info new file mode 100644 index 0000000..87902dd Binary files /dev/null and b/icons/BSDSocket-Extension/LICENSE.info differ diff --git a/icons/BSDSocket-Extension/README.md.info b/icons/BSDSocket-Extension/README.md.info new file mode 100644 index 0000000..2fdb58e Binary files /dev/null and b/icons/BSDSocket-Extension/README.md.info differ diff --git a/icons/BSDSocket-Extension/examples.info b/icons/BSDSocket-Extension/examples.info new file mode 100644 index 0000000..76ea79f Binary files /dev/null and b/icons/BSDSocket-Extension/examples.info differ diff --git a/icons/BSDSocket-Extension/src.info b/icons/BSDSocket-Extension/src.info new file mode 100644 index 0000000..c1b7788 Binary files /dev/null and b/icons/BSDSocket-Extension/src.info differ diff --git a/the minimum.amos b/the minimum.amos deleted file mode 100644 index 8720d01..0000000 Binary files a/the minimum.amos and /dev/null differ diff --git a/updated sockaddr in.amos b/updated sockaddr in.amos deleted file mode 100644 index 69eeabc..0000000 Binary files a/updated sockaddr in.amos and /dev/null differ